-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate EmailVerification to pg (#9492)
Signed-off-by: Matt Krick <[email protected]> Co-authored-by: Matt Krick <[email protected]>
- Loading branch information
Showing
7 changed files
with
108 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/server/postgres/migrations/1721868364099_addEmailVerification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {Kysely, PostgresDialect, sql} from 'kysely' | ||
import {Client} from 'pg' | ||
import {r} from 'rethinkdb-ts' | ||
import connectRethinkDB from '../../database/connectRethinkDB' | ||
import getPg from '../getPg' | ||
import getPgConfig from '../getPgConfig' | ||
|
||
export async function up() { | ||
await connectRethinkDB() | ||
const pg = new Kysely<any>({ | ||
dialect: new PostgresDialect({ | ||
pool: getPg() | ||
}) | ||
}) | ||
await sql` | ||
CREATE TABLE "EmailVerification" ( | ||
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | ||
"email" "citext" NOT NULL, | ||
"expiration" TIMESTAMP WITH TIME ZONE NOT NULL, | ||
"token" VARCHAR(100) NOT NULL, | ||
"hashedPassword" VARCHAR(100), | ||
"invitationToken" VARCHAR(100), | ||
"pseudoId" VARCHAR(100) | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_EmailVerification_email" ON "EmailVerification"("email"); | ||
CREATE INDEX IF NOT EXISTS "idx_EmailVerification_token" ON "EmailVerification"("token"); | ||
`.execute(pg) | ||
|
||
const rData = await r.table('EmailVerification').coerceTo('array').run() | ||
const insertData = rData.map((row) => { | ||
const {email, expiration, hashedPassword, token, invitationToken, pseudoId} = row | ||
return { | ||
email, | ||
expiration, | ||
hashedPassword, | ||
token, | ||
invitationToken, | ||
pseudoId | ||
} | ||
}) | ||
if (insertData.length === 0) return | ||
await pg.insertInto('EmailVerification').values(insertData).execute() | ||
} | ||
|
||
export async function down() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
DROP TABLE IF EXISTS "EmailVerification"; | ||
`) | ||
await client.end() | ||
} |