# -*- coding: utf-8 -*- """初始化数据库并导入初始数据(带官网链接)""" import os import sys # 确保项目根目录在 path 中 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from app import app, db from models import VPSPlan # 默认官网链接(可按方案自定义) DEFAULT_URLS = { "阿里云": "https://www.aliyun.com/product/ecs", "腾讯云": "https://cloud.tencent.com/product/cvm", "华为云": "https://www.huaweicloud.com/product/ecs.html", "DigitalOcean": "https://www.digitalocean.com/pricing/droplets", "Vultr": "https://www.vultr.com/pricing/", "Linode": "https://www.linode.com/pricing/", "AWS Lightsail": "https://aws.amazon.com/cn/lightsail/pricing/", } INITIAL_PLANS = [ {"provider": "阿里云", "region": "中国大陆", "name": "ecs.t6-c1m2.large", "vcpu": 2, "memory_gb": 4, "storage_gb": 40, "bandwidth_mbps": 1, "price_cny": 89, "price_usd": 12, "currency": "CNY"}, {"provider": "阿里云", "region": "中国大陆", "name": "ecs.c6.large", "vcpu": 2, "memory_gb": 4, "storage_gb": 100, "bandwidth_mbps": 5, "price_cny": 199, "price_usd": 28, "currency": "CNY"}, {"provider": "阿里云", "region": "中国大陆", "name": "ecs.c6.xlarge", "vcpu": 4, "memory_gb": 8, "storage_gb": 100, "bandwidth_mbps": 5, "price_cny": 398, "price_usd": 56, "currency": "CNY"}, {"provider": "腾讯云", "region": "中国大陆", "name": "S5.MEDIUM4", "vcpu": 2, "memory_gb": 4, "storage_gb": 50, "bandwidth_mbps": 1, "price_cny": 95, "price_usd": 13, "currency": "CNY"}, {"provider": "腾讯云", "region": "中国大陆", "name": "S5.LARGE8", "vcpu": 4, "memory_gb": 8, "storage_gb": 100, "bandwidth_mbps": 5, "price_cny": 379, "price_usd": 53, "currency": "CNY"}, {"provider": "华为云", "region": "中国大陆", "name": "s6.medium.2", "vcpu": 2, "memory_gb": 4, "storage_gb": 40, "bandwidth_mbps": 1, "price_cny": 99, "price_usd": 14, "currency": "CNY"}, {"provider": "华为云", "region": "中国大陆", "name": "s6.large.4", "vcpu": 4, "memory_gb": 8, "storage_gb": 100, "bandwidth_mbps": 5, "price_cny": 358, "price_usd": 50, "currency": "CNY"}, {"provider": "DigitalOcean", "region": "全球多区域", "name": "Basic Droplet", "vcpu": 1, "memory_gb": 1, "storage_gb": 25, "bandwidth_mbps": 1000, "price_cny": 42, "price_usd": 6, "currency": "USD"}, {"provider": "DigitalOcean", "region": "全球多区域", "name": "Basic Droplet", "vcpu": 1, "memory_gb": 2, "storage_gb": 50, "bandwidth_mbps": 2000, "price_cny": 70, "price_usd": 10, "currency": "USD"}, {"provider": "DigitalOcean", "region": "全球多区域", "name": "Basic Droplet", "vcpu": 2, "memory_gb": 4, "storage_gb": 80, "bandwidth_mbps": 4000, "price_cny": 140, "price_usd": 20, "currency": "USD"}, {"provider": "Vultr", "region": "全球多区域", "name": "Cloud Compute", "vcpu": 1, "memory_gb": 1, "storage_gb": 25, "bandwidth_mbps": 1000, "price_cny": 35, "price_usd": 5, "currency": "USD"}, {"provider": "Vultr", "region": "全球多区域", "name": "Cloud Compute", "vcpu": 1, "memory_gb": 2, "storage_gb": 55, "bandwidth_mbps": 2000, "price_cny": 70, "price_usd": 10, "currency": "USD"}, {"provider": "Vultr", "region": "全球多区域", "name": "Cloud Compute", "vcpu": 2, "memory_gb": 4, "storage_gb": 80, "bandwidth_mbps": 3000, "price_cny": 140, "price_usd": 20, "currency": "USD"}, {"provider": "Linode", "region": "全球多区域", "name": "Nanode", "vcpu": 1, "memory_gb": 1, "storage_gb": 25, "bandwidth_mbps": 1000, "price_cny": 35, "price_usd": 5, "currency": "USD"}, {"provider": "Linode", "region": "全球多区域", "name": "Linode 2GB", "vcpu": 1, "memory_gb": 2, "storage_gb": 50, "bandwidth_mbps": 2000, "price_cny": 70, "price_usd": 10, "currency": "USD"}, {"provider": "Linode", "region": "全球多区域", "name": "Linode 4GB", "vcpu": 2, "memory_gb": 4, "storage_gb": 80, "bandwidth_mbps": 4000, "price_cny": 140, "price_usd": 20, "currency": "USD"}, {"provider": "AWS Lightsail", "region": "全球多区域", "name": "$5 Plan", "vcpu": 1, "memory_gb": 1, "storage_gb": 40, "bandwidth_mbps": 2000, "price_cny": 35, "price_usd": 5, "currency": "USD"}, {"provider": "AWS Lightsail", "region": "全球多区域", "name": "$10 Plan", "vcpu": 1, "memory_gb": 2, "storage_gb": 60, "bandwidth_mbps": 3000, "price_cny": 70, "price_usd": 10, "currency": "USD"}, {"provider": "AWS Lightsail", "region": "全球多区域", "name": "$20 Plan", "vcpu": 2, "memory_gb": 4, "storage_gb": 80, "bandwidth_mbps": 4000, "price_cny": 140, "price_usd": 20, "currency": "USD"}, ] def main(): with app.app_context(): db.create_all() if VPSPlan.query.count() == 0: for p in INITIAL_PLANS: plan = VPSPlan( official_url=DEFAULT_URLS.get(p["provider"], ""), **p, ) db.session.add(plan) db.session.commit() print("已导入 %d 条初始方案。" % len(INITIAL_PLANS)) else: print("数据库中已有数据,跳过导入。若要重新初始化请删除 vps_price.db 后重试。") if __name__ == "__main__": main()