Skip to content

Commit

Permalink
fix schema escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Jan 17, 2025
1 parent da9266f commit 65d8cec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const client = ({ db }: { db: ReadonlyDrizzle<Schema> }) => {
const channel = `${globalThis.PONDER_NAMESPACE_BUILD}_status_channel`;

if ("instance" in driver) {
driver.instance.query(`LISTEN ${channel}`).then(() => {
driver.instance.query(`LISTEN "${channel}"`).then(() => {
driver.instance.onNotification(async () => {
statusResolver.resolve();
statusResolver = promiseWithResolvers();
Expand All @@ -52,7 +52,7 @@ export const client = ({ db }: { db: ReadonlyDrizzle<Schema> }) => {
const connectAndListen = async () => {
driver.listen = await pool.connect();

await driver.listen.query(`LISTEN ${channel}`);
await driver.listen.query(`LISTEN "${channel}"`);

driver.listen.on("error", async () => {
driver.listen?.release();
Expand Down
26 changes: 13 additions & 13 deletions packages/core/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export const createDatabase = async ({

const role =
connection.database === undefined
? `ponder_readonly_${namespace}`
: `ponder_readonly_${connection.database}_${namespace}`;
? `ponder_${namespace}`
: `ponder_${connection.database}_${namespace}`;

await internal.query(`CREATE SCHEMA IF NOT EXISTS "${namespace}"`);
const hasRole = await internal
Expand Down Expand Up @@ -793,8 +793,8 @@ export const createDatabase = async ({
.selectFrom("_ponder_meta")
.select("value")
.where("key", "=", "app")
.executeTakeFirstOrThrow()
.then((row) => row.value.version);
.executeTakeFirst()
.then((row) => row?.value.version);

if (version === undefined || Number(version) < Number(VERSION)) {
await qb.internal.schema
Expand Down Expand Up @@ -825,29 +825,29 @@ export const createDatabase = async ({
.execute();

const trigger = "status_trigger";
const notification = `${namespace}_status_notify()`;
const notification = "status_notify()";
const channel = `${namespace}_status_channel`;

await sql
.raw(`
CREATE OR REPLACE FUNCTION ${notification}
RETURNS trigger
CREATE OR REPLACE FUNCTION "${namespace}".${notification}
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
NOTIFY ${channel};
NOTIFY "${channel}";
RETURN NULL;
END;
$$;`)
.execute(qb.internal);

await sql
.raw(`
CREATE OR REPLACE TRIGGER ${trigger}
AFTER INSERT OR UPDATE OR DELETE
ON "${namespace}"._ponder_status
FOR EACH STATEMENT
EXECUTE PROCEDURE ${notification};`)
CREATE OR REPLACE TRIGGER "${trigger}"
AFTER INSERT OR UPDATE OR DELETE
ON "${namespace}"._ponder_status
FOR EACH STATEMENT
EXECUTE PROCEDURE "${namespace}".${notification};`)
.execute(qb.internal);
},
);
Expand Down

0 comments on commit 65d8cec

Please sign in to comment.