Skip to content

Commit 3646565

Browse files
committed
feat: add is_vanished column to users table
1 parent 4b2b032 commit 3646565

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
exports.up = async function (knex) {
2+
await knex.schema.alterTable('users', (table) => {
3+
table.boolean('is_vanished').notNullable().defaultTo(false)
4+
})
5+
6+
await knex.raw(`
7+
UPDATE users u
8+
SET is_vanished = true
9+
FROM events e
10+
WHERE u.pubkey = e.event_pubkey
11+
AND e.event_kind = 62
12+
AND e.deleted_at IS NULL
13+
`)
14+
15+
await knex.raw(`
16+
INSERT INTO users (pubkey, is_admitted, balance, is_vanished, created_at, updated_at)
17+
SELECT DISTINCT e.event_pubkey, false, 0, true, NOW(), NOW()
18+
FROM events e
19+
LEFT JOIN users u ON u.pubkey = e.event_pubkey
20+
WHERE e.event_kind = 62
21+
AND e.deleted_at IS NULL
22+
AND u.pubkey IS NULL
23+
`)
24+
}
25+
26+
exports.down = function (knex) {
27+
return knex.schema.alterTable('users', (table) => {
28+
table.dropColumn('is_vanished')
29+
})
30+
}

0 commit comments

Comments
 (0)