-
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(rethinkdb): QueryMap: One-shot (#10005)
Signed-off-by: Matt Krick <[email protected]>
- Loading branch information
Showing
7 changed files
with
63 additions
and
22 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 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
36 changes: 36 additions & 0 deletions
36
packages/server/postgres/migrations/1721348544381_QueryMapOneShot.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,36 @@ | ||
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 IF NOT EXISTS "QueryMap" ( | ||
"id" VARCHAR(24) PRIMARY KEY, | ||
"query" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() | ||
) | ||
`.execute(pg) | ||
const queries = await r | ||
.table('QueryMap') | ||
.filter((row) => row('createdAt').default(null).ne(null)) | ||
.run() | ||
await pg.insertInto('QueryMap').values(queries).execute() | ||
} | ||
|
||
export async function down() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
DROP TABLE "QueryMap"; | ||
` /* Do undo magic */) | ||
await client.end() | ||
} |
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