diff --git a/db/migrations/20241022093002_create_subscription_plans_table.js b/db/migrations/20241022093002_create_subscription_plans_table.js new file mode 100644 index 0000000..6c64a9f --- /dev/null +++ b/db/migrations/20241022093002_create_subscription_plans_table.js @@ -0,0 +1,17 @@ +export function up(knex) { + return knex.schema.createTable('subscription_plans', function(table) { + table.increments('_id').primary().comment('主键ID'); + table.string('name', 50).notNullable().unique().comment('计划名称'); + table.integer('tokens').unsigned().notNullable().comment('代币数量'); + table.decimal('price', 10, 2).notNullable().comment('月度价格'); + table.text('description').comment('计划描述'); + table.integer('save_percentage').unsigned().comment('节省百分比'); + table.boolean('is_active').defaultTo(true).comment('是否激活'); + table.timestamp('_create').defaultTo(knex.fn.now()).comment('创建时间'); + table.timestamp('_update').defaultTo(knex.fn.now()).comment('更新时间'); + }); +} + +export function down(knex) { + return knex.schema.dropTable('subscription_plans'); +} diff --git a/db/migrations/20241022093003_insert_initial_subscription_plans.js b/db/migrations/20241022093003_insert_initial_subscription_plans.js new file mode 100644 index 0000000..c8d5519 --- /dev/null +++ b/db/migrations/20241022093003_insert_initial_subscription_plans.js @@ -0,0 +1,36 @@ +export function up(knex) { + return knex('subscription_plans').insert([ + { + name: 'Pro', + tokens: 10000000, + price: 20.00, + description: '适合业余爱好者和轻度探索性使用的休闲用户。', + save_percentage: null, + }, + { + name: 'Pro 50', + tokens: 26000000, + price: 50.00, + description: '为每周需要使用多八多几次的专业人士设计。', + save_percentage: 3, + }, + { + name: 'Pro 100', + tokens: 55000000, + price: 100.00, + description: '完美适合希望提升日常工作流程的重度用户。', + save_percentage: 9, + }, + { + name: 'Pro 200', + tokens: 120000000, + price: 200.00, + description: '最适合依赖多八多作为核心工具持续使用的超级用户。', + save_percentage: 17, + }, + ]); +} + +export function down(knex) { + return knex('subscription_plans').del(); +} diff --git a/db/migrations/20241022093004_create_token_reloads_table.js b/db/migrations/20241022093004_create_token_reloads_table.js new file mode 100644 index 0000000..a625aaf --- /dev/null +++ b/db/migrations/20241022093004_create_token_reloads_table.js @@ -0,0 +1,16 @@ +export function up(knex) { + return knex.schema.createTable('token_reloads', function(table) { + table.increments('_id').primary().comment('主键ID'); + table.string('name', 50).notNullable().unique().comment('充值包名称'); + table.integer('tokens').unsigned().notNullable().comment('代币数量'); + table.decimal('price', 10, 2).notNullable().comment('价格'); + table.text('description').comment('描述'); + table.boolean('is_active').defaultTo(true).comment('是否激活'); + table.timestamp('_create').defaultTo(knex.fn.now()).comment('创建时间'); + table.timestamp('_update').defaultTo(knex.fn.now()).comment('更新时间'); + }); +} + +export function down(knex) { + return knex.schema.dropTable('token_reloads'); +} diff --git a/db/migrations/20241022093005_insert_initial_token_reload.js b/db/migrations/20241022093005_insert_initial_token_reload.js new file mode 100644 index 0000000..c18ec88 --- /dev/null +++ b/db/migrations/20241022093005_insert_initial_token_reload.js @@ -0,0 +1,14 @@ +export function up(knex) { + return knex('token_reloads').insert([ + { + name: '代币充值', + tokens: 10000000, + price: 20.00, + description: '非订阅代币购买,每次充值10,000,000代币', + } + ]); +} + +export function down(knex) { + return knex('token_reloads').del(); +} diff --git a/db/migrations/20241022093006_create_chat_histories_table.js b/db/migrations/20241022093006_create_chat_histories_table.js new file mode 100644 index 0000000..027cb7a --- /dev/null +++ b/db/migrations/20241022093006_create_chat_histories_table.js @@ -0,0 +1,19 @@ +export function up(knex) { + return knex.schema.createTable('chat_histories', function(table) { + table.increments('_id').primary().comment('主键ID'); + table.integer('user_id').unsigned().notNullable().comment('用户ID'); + table.foreign('user_id').references('users._id').onDelete('CASCADE'); + table.text('message').notNullable().comment('消息内容'); + table.enum('role', ['user', 'assistant']).notNullable().comment('消息角色'); + table.integer('tokens_used').unsigned().comment('使用的代币数量'); + table.string('session_id', 255).comment('会话ID'); + table.timestamp('_create').defaultTo(knex.fn.now()).comment('创建时间'); + table.timestamp('_update').defaultTo(knex.fn.now()).comment('更新时间'); + table.index('user_id'); + table.index('session_id'); + }); +} + +export function down(knex) { + return knex.schema.dropTable('chat_histories'); +}