This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-social-columns.ts
More file actions
75 lines (66 loc) · 2.2 KB
/
Copy pathadd-social-columns.ts
File metadata and controls
75 lines (66 loc) · 2.2 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
64
65
66
67
68
69
70
71
72
73
74
75
import { pool, db } from './db';
import { sql } from 'drizzle-orm';
async function main() {
try {
console.log("Adding social-related columns to users table...");
// Add each column if it doesn't exist
const columnsToAdd = [
// OAuth related columns
"googleIdHash text",
"googleVerified boolean DEFAULT false",
"youtubeIdHash text",
"youtubeVerified boolean DEFAULT false",
"youtubeSubscribers integer",
"githubIdHash text",
"githubVerified boolean DEFAULT false",
"githubFollowers integer",
"discordIdHash text",
"discordVerified boolean DEFAULT false",
"discordUsername text",
// Social media columns
"telegramId integer",
"telegramUsername text",
"telegramVerified boolean DEFAULT false",
"telegramFollowers integer",
"instagramUsername text",
"instagramVerified boolean DEFAULT false",
"instagramFollowers integer",
"xIdHash text",
"xUsername text",
"xVerified boolean DEFAULT false",
"xFollowers integer",
"facebookIdHash text",
"facebookVerified boolean DEFAULT false",
"facebookFriends integer",
"linkedinIdHash text",
"linkedinVerified boolean DEFAULT false",
"linkedinConnections integer"
];
let addedColumns = 0;
for (const columnDef of columnsToAdd) {
const columnName = columnDef.split(' ')[0];
// Check if column exists
const result = await pool.query(`
SELECT column_name
FROM information_schema.columns
WHERE table_name='users' AND column_name='${columnName}'
`);
if (result.rows.length === 0) {
// Add the column
await pool.query(`ALTER TABLE users ADD COLUMN IF NOT EXISTS ${columnDef}`);
console.log(`Added column: ${columnName}`);
addedColumns++;
} else {
console.log(`Column already exists: ${columnName}`);
}
}
console.log(`Added ${addedColumns} columns to the users table`);
console.log("Migration completed successfully");
} catch (error) {
console.error("Migration failed:", error);
process.exit(1);
} finally {
await pool.end();
}
}
main();