Skip to content

Commit db08546

Browse files
committed
chore: switch db migration to use sequelize migration
1 parent 948c2c8 commit db08546

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** @type {import('sequelize-cli').Migration} */
2+
module.exports = {
3+
async up(queryInterface, Sequelize) {
4+
/**
5+
* Add altering commands here.
6+
*
7+
* Example:
8+
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });.
9+
*/
10+
await queryInterface.addColumn('urls', 'safeBrowsingExpiry', {
11+
type: Sequelize.DATE,
12+
allowNull: true,
13+
defaultValue: null,
14+
})
15+
},
16+
17+
async down(queryInterface) {
18+
/**
19+
* Add reverting commands here.
20+
*
21+
* Example:
22+
* await queryInterface.dropTable('users');.
23+
*/
24+
await queryInterface.removeColumn('urls', 'safeBrowsingExpiry')
25+
},
26+
}

src/server/db_migrations/20250721_add_urls_safebrowsing_expiry.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/server/models/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UrlClicks } from './statistics/clicks'
88
import { syncFunctions } from './functions'
99
import { Tag } from './tag'
1010
import { Job, JobItem } from './job'
11+
import { DEV_ENV } from '../config'
1112

1213
// One user can create many urls but each url can only be mapped to one user.
1314
User.hasMany(Url, { as: 'Urls', foreignKey: { allowNull: false } })
@@ -45,6 +46,8 @@ UrlClicks.belongsTo(Url, { foreignKey: 'shortUrl' })
4546
* Initialise the database table.
4647
*/
4748
export default async () => {
48-
await sequelize.sync()
49+
if (DEV_ENV) {
50+
await sequelize.sync()
51+
}
4952
await syncFunctions()
5053
}

0 commit comments

Comments
 (0)