-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmigrate-channels.js
More file actions
63 lines (55 loc) · 1.63 KB
/
migrate-channels.js
File metadata and controls
63 lines (55 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Sequelize } from 'sequelize';
const sequelize = new Sequelize(
'odevtube',
'devuser',
'devpass',
{
host: 'localhost',
dialect: 'mariadb',
logging: console.log,
}
);
async function migrate() {
try {
console.log('Connecting to database...');
await sequelize.authenticate();
console.log('Connected successfully.');
// Check if isPublic column exists
const results = await sequelize.query(
"SHOW COLUMNS FROM channels LIKE 'isPublic'",
{ type: sequelize.QueryTypes.SELECT }
);
if (results.length === 0) {
console.log('Adding isPublic column...');
await sequelize.query(
'ALTER TABLE channels ADD COLUMN isPublic TINYINT(1) DEFAULT 1',
{ type: sequelize.QueryTypes.RAW }
);
console.log('isPublic column added successfully.');
} else {
console.log('isPublic column already exists.');
}
// Check if accountId column exists
const results2 = await sequelize.query(
"SHOW COLUMNS FROM channels LIKE 'accountId'",
{ type: sequelize.QueryTypes.SELECT }
);
if (results2.length === 0) {
console.log('Adding accountId column...');
await sequelize.query(
'ALTER TABLE channels ADD COLUMN accountId VARCHAR(255)',
{ type: sequelize.QueryTypes.RAW }
);
console.log('accountId column added successfully.');
} else {
console.log('accountId column already exists.');
}
console.log('Migration completed successfully!');
} catch (error) {
console.error('Migration failed:', error);
process.exit(1);
} finally {
await sequelize.close();
}
}
migrate();