Skip to content

Commit 1058f15

Browse files
committed
total_user_count migration
1 parent bc1f718 commit 1058f15

4 files changed

+49
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { DataTypes } from 'sequelize'
2+
3+
import type { Migration } from '../connection'
4+
5+
export const up: Migration = async ({ context: queryInterface }) => {
6+
await queryInterface.addColumn('user_chat_instance_usages', 'totalUsageCount', {
7+
type: DataTypes.INTEGER,
8+
allowNull: false,
9+
defaultValue: 0,
10+
})
11+
}
12+
13+
export const down: Migration = async ({ context: queryInterface }) => {
14+
await queryInterface.removeColumn('user_chat_instance_usages', 'totalUsageCount')
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DataTypes } from 'sequelize'
2+
3+
import type { Migration } from '../connection'
4+
5+
export const up: Migration = async ({ context: queryInterface }) => {
6+
await queryInterface.renameColumn('user_chat_instance_usages', 'totalUsageCount', 'total_usage_count')
7+
}
8+
9+
export const down: Migration = async ({ context: queryInterface }) => {
10+
await queryInterface.renameColumn('user_chat_instance_usages', 'total_usage_count', 'totalUsageCount')
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Migration } from '../connection'
2+
3+
export const up: Migration = async ({ context: queryInterface }) => {
4+
await queryInterface.sequelize.query(`
5+
UPDATE user_chat_instance_usages
6+
SET total_usage_count = usage_count
7+
WHERE total_usage_count IS NULL OR total_usage_count = 0;
8+
`)
9+
}
10+
11+
export const down: Migration = async ({ context: queryInterface }) => {
12+
await queryInterface.sequelize.query(`
13+
UPDATE user_chat_instance_usages
14+
SET total_usage_count = 0;
15+
`)
16+
}

src/server/db/models/userChatInstanceUsage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class UserChatInstanceUsage extends Model<InferAttributes<UserChatInstanceUsage>
1010
declare chatInstanceId: string
1111

1212
declare usageCount: CreationOptional<number>
13+
14+
declare totalUsageCount: CreationOptional<number>
1315
}
1416

1517
UserChatInstanceUsage.init(
@@ -33,6 +35,11 @@ UserChatInstanceUsage.init(
3335
allowNull: false,
3436
defaultValue: 0,
3537
},
38+
totalUsageCount: {
39+
type: DataTypes.INTEGER,
40+
allowNull: false,
41+
defaultValue: 0,
42+
},
3643
},
3744
{
3845
underscored: true,

0 commit comments

Comments
 (0)