240 lines
12 KiB
Python
240 lines
12 KiB
Python
|
from tortoise import BaseDBAsyncClient
|
||
|
|
||
|
|
||
|
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||
|
return """
|
||
|
CREATE TABLE IF NOT EXISTS `users` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`nickname` VARCHAR(30) COMMENT '用户昵称',
|
||
|
`avatar_url` VARCHAR(255) COMMENT '头像',
|
||
|
`member_type` INT COMMENT '会员类型',
|
||
|
`beta_account_type` VARCHAR(30) COMMENT '内测账号类型',
|
||
|
`pre_cost_time` INT COMMENT '预支付时间(单位年)',
|
||
|
`qr_code` VARCHAR(255) COMMENT '专属客服二维码',
|
||
|
`dedicated_id` INT COMMENT '专属客服id',
|
||
|
`invited_user_id` INT COMMENT '邀请人id',
|
||
|
`created_user_id` INT COMMENT '创建人id',
|
||
|
`is_deleted` BOOL NOT NULL COMMENT '是否删除' DEFAULT 0,
|
||
|
`login_at` DATETIME(6) COMMENT '最后一次登录时间',
|
||
|
`created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
|
||
|
`updated_at` DATETIME(6) NOT NULL COMMENT '修改时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||
|
`deleted_at` DATETIME(6) COMMENT '删除时间',
|
||
|
KEY `idx_users_is_dele_9cdc79` (`is_deleted`)
|
||
|
) CHARACTER SET utf8mb4 COMMENT='用户';
|
||
|
CREATE TABLE IF NOT EXISTS `stock` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`stock_code` VARCHAR(30) NOT NULL COMMENT '股票代码',
|
||
|
`stock_name` VARCHAR(30) COMMENT '股票名称',
|
||
|
`type` VARCHAR(2) COMMENT '类型',
|
||
|
`stock_pinyin` VARCHAR(30) NOT NULL COMMENT '股票拼音'
|
||
|
) CHARACTER SET utf8mb4 COMMENT='股票相关信息';
|
||
|
CREATE TABLE IF NOT EXISTS `security_account` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`securities_name` VARCHAR(30) NOT NULL COMMENT '证券公司名字昵称',
|
||
|
`fund_account` BIGINT COMMENT '资金账户',
|
||
|
`account_alias` VARCHAR(30) NOT NULL COMMENT '账户别名',
|
||
|
`money` DOUBLE COMMENT '账户金额',
|
||
|
`available_money` DOUBLE COMMENT '可用金额',
|
||
|
`available_proportion` DOUBLE COMMENT '可用资金占比',
|
||
|
`freeze` DOUBLE COMMENT '冻结金额'
|
||
|
) CHARACTER SET utf8mb4 COMMENT='证券账户';
|
||
|
CREATE TABLE IF NOT EXISTS `backtest` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键id',
|
||
|
`key` VARCHAR(30) NOT NULL COMMENT '回测key'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `Entrust` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键id',
|
||
|
`fund_account` INT COMMENT '资金账户',
|
||
|
`securities_alias` VARCHAR(30) COMMENT '账户别名',
|
||
|
`account_type` SMALLINT COMMENT '账户类型',
|
||
|
`stock_code` VARCHAR(30) NOT NULL COMMENT '证券代码',
|
||
|
`stock_name` VARCHAR(30) NOT NULL COMMENT '证券名称',
|
||
|
`limit_price` DOUBLE NOT NULL COMMENT '委托价',
|
||
|
`entrust_number` INT NOT NULL COMMENT '委托数量',
|
||
|
`deal_price` DOUBLE COMMENT '成交价格',
|
||
|
`deal_number` INT COMMENT '成家数量',
|
||
|
`order_type` VARCHAR(30) NOT NULL COMMENT '操作',
|
||
|
`entrust_date` DATE COMMENT '委托日期',
|
||
|
`entrust_money` DOUBLE NOT NULL COMMENT '委托金额',
|
||
|
`is_repair` BOOL NOT NULL COMMENT '是否补单' DEFAULT 0,
|
||
|
`entrust_time` TIME(6),
|
||
|
KEY `idx_Entrust_is_repa_5a195d` (`is_repair`)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `orders` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '订单ID',
|
||
|
`stock_code` VARCHAR(30) NOT NULL COMMENT '股票代码',
|
||
|
`stock_name` VARCHAR(30) NOT NULL COMMENT '股票名称',
|
||
|
`limit_price` DOUBLE NOT NULL COMMENT '限价',
|
||
|
`order_quantity` INT NOT NULL COMMENT '委托数量',
|
||
|
`order_amount` DOUBLE NOT NULL COMMENT '委托金额',
|
||
|
`order_type` VARCHAR(20) NOT NULL COMMENT '订单类型',
|
||
|
`position` VARCHAR(30) NOT NULL COMMENT '仓位',
|
||
|
`user_id` INT NOT NULL COMMENT '用户Id',
|
||
|
`entrust_date` DATETIME(6) COMMENT '委托日期',
|
||
|
`entrust_time` TIME(6)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `snowball` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`snowball_token` VARCHAR(10000) COMMENT '雪球用户的token'
|
||
|
) CHARACTER SET utf8mb4 COMMENT='雪球相关信息';
|
||
|
CREATE TABLE IF NOT EXISTS `Strategy` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`strategy_name` VARCHAR(255) NOT NULL COMMENT '策略名称',
|
||
|
`strategy_hash` VARCHAR(255) NOT NULL COMMENT '策略版本号',
|
||
|
`strategy_type` VARCHAR(255) COMMENT '策略类型',
|
||
|
`user_id` INT COMMENT '所属用户',
|
||
|
`backtest_count` INT COMMENT '回测次数',
|
||
|
`backtest_keys` JSON COMMENT '回测key列表',
|
||
|
`is_deleted` BOOL NOT NULL COMMENT '是否删除' DEFAULT 0,
|
||
|
`created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
|
||
|
`updated_at` DATETIME(6) NOT NULL COMMENT '修改时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||
|
`deleted_at` DATETIME(6) COMMENT '删除时间'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `Backtest` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(20) NOT NULL UNIQUE COMMENT '回测key',
|
||
|
`user_id` INT COMMENT '回测用户',
|
||
|
`backtest_at` DATETIME(6) NOT NULL COMMENT '回测时间' DEFAULT CURRENT_TIMESTAMP(6),
|
||
|
`backtest_code` LONGTEXT NOT NULL COMMENT '回测代码',
|
||
|
`is_running` BOOL NOT NULL COMMENT '回测状态' DEFAULT 1,
|
||
|
`updated_at` DATETIME(6) NOT NULL COMMENT '修改时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||
|
`deleted_at` DATETIME(6) COMMENT '删除时间',
|
||
|
`is_active` BOOL NOT NULL COMMENT '是否可用' DEFAULT 1,
|
||
|
`strategy_id` INT NOT NULL,
|
||
|
CONSTRAINT `fk_Backtest_Strategy_7eabb20d` FOREIGN KEY (`strategy_id`) REFERENCES `Strategy` (`id`) ON DELETE CASCADE,
|
||
|
KEY `idx_Backtest_key_eb92b1` (`key`),
|
||
|
KEY `idx_Backtest_strateg_83ac3d` (`strategy_id`)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `stock_details` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`stock_code` VARCHAR(30) NOT NULL COMMENT '股票代码',
|
||
|
`stock_name` VARCHAR(30) COMMENT '股票名称',
|
||
|
`type` VARCHAR(2) COMMENT '类型',
|
||
|
`stock_pinyin` VARCHAR(30) NOT NULL COMMENT '股票拼音',
|
||
|
`latest_price` DOUBLE COMMENT '最新价',
|
||
|
`rise_fall` DOUBLE COMMENT '跌涨幅'
|
||
|
) CHARACTER SET utf8mb4 COMMENT='股票相关信息';
|
||
|
CREATE TABLE IF NOT EXISTS `Transaction` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`key` VARCHAR(20) NOT NULL COMMENT 'key,数据标识',
|
||
|
`cash` DOUBLE COMMENT '资金',
|
||
|
`transaction_name` VARCHAR(255) NOT NULL COMMENT '交易名称',
|
||
|
`transaction_type` VARCHAR(255) COMMENT '交易类型',
|
||
|
`user_id` INT COMMENT '用户id',
|
||
|
`is_running` BOOL NOT NULL COMMENT '运行状态' DEFAULT 1,
|
||
|
`is_deleted` BOOL NOT NULL COMMENT '是否删除' DEFAULT 0,
|
||
|
`process_id` INT COMMENT '进程号',
|
||
|
`bar` VARCHAR(10) COMMENT '频率K线',
|
||
|
`created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
|
||
|
`updated_at` DATETIME(6) NOT NULL COMMENT '修改时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||
|
`stopped_at` DATETIME(6) COMMENT '停止时间',
|
||
|
`deleted_at` DATETIME(6) COMMENT '删除时间',
|
||
|
`strategy_id` INT NOT NULL,
|
||
|
CONSTRAINT `fk_Transact_Strategy_849d0577` FOREIGN KEY (`strategy_id`) REFERENCES `Strategy` (`id`) ON DELETE CASCADE,
|
||
|
KEY `idx_Transaction_strateg_b8f0b2` (`strategy_id`)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `position` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键',
|
||
|
`key` VARCHAR(30) NOT NULL COMMENT '键',
|
||
|
`date` DATE NOT NULL COMMENT '日期',
|
||
|
`name` VARCHAR(30) NOT NULL COMMENT '名称',
|
||
|
`size` INT NOT NULL COMMENT '数量',
|
||
|
`price` DOUBLE NOT NULL COMMENT '价格',
|
||
|
`adjbase` DOUBLE NOT NULL COMMENT '复权基数',
|
||
|
`profit` DOUBLE NOT NULL COMMENT '利润'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `trand_info` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'id',
|
||
|
`key` VARCHAR(255) COMMENT '唯一索引',
|
||
|
`tran_info_data` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `tran_observer_data` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(255) NOT NULL,
|
||
|
`tran_observer_data` LONGBLOB COMMENT '存储大量数据'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `tranorders` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(255),
|
||
|
`order_return` VARCHAR(255)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `tran_return` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(255),
|
||
|
`tran_return_data` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `tran_trade_info` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(25),
|
||
|
`tran_trade_info` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `back_observed_data` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'id表',
|
||
|
`key` VARCHAR(255) COMMENT 'key',
|
||
|
`observed_data` LONGBLOB COMMENT '格式化后的json数据'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `back_observed_data_detail` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(255) NOT NULL,
|
||
|
`back_observed_data` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `back_position` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(25),
|
||
|
`back_position_data` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `back_result_indicator` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(25),
|
||
|
`indicator` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `back_trand_info` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(25),
|
||
|
`trade_info` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `tran_position` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`key` VARCHAR(25),
|
||
|
`tran_position_data` LONGBLOB
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `stock_bt_history` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`end_bt_time` VARCHAR(8) COMMENT '回测最终时间',
|
||
|
`bt_stock_code` VARCHAR(8) COMMENT '回测股票代码',
|
||
|
`bt_stock_name` VARCHAR(10) COMMENT '回测股票名称',
|
||
|
`bt_benchmark_code` VARCHAR(8) COMMENT '股票基准代码',
|
||
|
`bt_stock_period` VARCHAR(10) COMMENT '回测类型',
|
||
|
`bt_strategy_name` VARCHAR(10) COMMENT '回测策略名称',
|
||
|
`bt_stock_data` LONGBLOB COMMENT '回测股票数据'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `stock_history` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`stock_code` INT NOT NULL COMMENT '股票代码',
|
||
|
`stock_name` VARCHAR(10),
|
||
|
`start_time_to_market` VARCHAR(10) COMMENT '股票上市时间',
|
||
|
`end_bt_time` VARCHAR(10) COMMENT '最终回测时间',
|
||
|
`symbol_data` LONGBLOB COMMENT '股票数据'
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `stock_data_processing` (
|
||
|
`bt_benchmark_code` VARCHAR(6) COMMENT '基准代码',
|
||
|
`bt_stock_period` VARCHAR(10) COMMENT '数据类型',
|
||
|
`bt_strategy_name` VARCHAR(10) COMMENT '回测策略名',
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`processing_data` LONGBLOB COMMENT '清洗后的数据',
|
||
|
`prosessing_date` VARCHAR(10) COMMENT '当前回测时间',
|
||
|
`stock_name` VARCHAR(10),
|
||
|
`stocke_code` VARCHAR(10)
|
||
|
) CHARACTER SET utf8mb4;
|
||
|
CREATE TABLE IF NOT EXISTS `aerich` (
|
||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||
|
`version` VARCHAR(255) NOT NULL,
|
||
|
`app` VARCHAR(100) NOT NULL,
|
||
|
`content` JSON NOT NULL
|
||
|
) CHARACTER SET utf8mb4;"""
|
||
|
|
||
|
|
||
|
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||
|
return """
|
||
|
"""
|