Mr Volcano
Mr Volcano
Explore posts from servers
DTDrizzle Team
Created by Mr Volcano on 11/3/2023 in #help
Appending SQL chunks to a query
Hey everyone, I'm trying to see if there is a way where I can build SQL queries conditionally (based on some search params I get)
13 replies
DTDrizzle Team
Created by Mr Volcano on 11/1/2023 in #help
Unable to run migrations
I have this small script I'm running to perform the db migrations:
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
import { db } from ".";

const runMigrations = async () => {
console.log("migration started...");
const res = await migrate(db, { migrationsFolder: "drizzle" });
console.log("migration performed succesfully!", res);
process.exit(0);
};

runMigrations().catch((err) => {
console.log("Error trying to apply migrations: ", err);
process.exit(0);
});
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
import { db } from ".";

const runMigrations = async () => {
console.log("migration started...");
const res = await migrate(db, { migrationsFolder: "drizzle" });
console.log("migration performed succesfully!", res);
process.exit(0);
};

runMigrations().catch((err) => {
console.log("Error trying to apply migrations: ", err);
process.exit(0);
});
I've made sure the migrationsFolder is the one I want, it has a sql migration file that looks like this (it has more fields ofc):
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "action_status" AS ENUM('PENDING', 'COMPLETED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "action_status" AS ENUM('PENDING', 'COMPLETED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
I get no erros but my db remains the same, you got any ideas ?
11 replies
DTDrizzle Team
Created by Mr Volcano on 10/24/2023 in #help
Postgres timestamp that will be the same across regions
Hello everyone, So I have a statement like the following:
CREATE TABLE your_table_name (
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
);
CREATE TABLE your_table_name (
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
);
Becaue I want my backend code to store the same timestamp no matter the region. But drizzle schema file is red on:
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)),
Because:
Cannot find name 'CURRENT_TIMESTAMP'
Cannot find name 'CURRENT_TIMESTAMP'
Will this cause me issues in the future ? All I'm trying to do is to have my backend set "created_at" the same across different regions. I'm pretty new so any suggestions would be great, thanks!
1 replies
DTDrizzle Team
Created by Mr Volcano on 10/19/2023 in #help
VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString'
Hello everyone! So I'm getting the following error while trying to use the @vercel/postgres package with drizzle ORM
VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
at createPool (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VGUHM5WG.js:150:34)
at Object.get (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VG
VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
at createPool (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VGUHM5WG.js:150:34)
at Object.get (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VG
Here is my db index.ts
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';

export const db = drizzle(sql)
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';

export const db = drizzle(sql)
As well as my drizzle.config.ts
import { loadEnvConfig } from "@next/env";
import type { Config } from "drizzle-kit";
import { cwd } from "process";

loadEnvConfig(cwd());

console.log("url", process.env.DEV_POSTGRES_URL);

let connectionString;

if (process.env.VERCEL_ENV === "production") {
connectionString = process.env.PROD_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "preview") {
connectionString = process.env.STAGING_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "development") {
connectionString = process.env.DEV_POSTGRES_URL;
}

export default {
schema: "./src/lib/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString
? connectionString + "?sslmode=require"
: "",
},
} as Config;
import { loadEnvConfig } from "@next/env";
import type { Config } from "drizzle-kit";
import { cwd } from "process";

loadEnvConfig(cwd());

console.log("url", process.env.DEV_POSTGRES_URL);

let connectionString;

if (process.env.VERCEL_ENV === "production") {
connectionString = process.env.PROD_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "preview") {
connectionString = process.env.STAGING_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "development") {
connectionString = process.env.DEV_POSTGRES_URL;
}

export default {
schema: "./src/lib/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString
? connectionString + "?sslmode=require"
: "",
},
} as Config;
Few notes: 1. The URL is provided in connectionString. I'm sure it's defined. I have even hardcoded it. I'm 99% sure that the case is that Vercel postgres doesn't really read it and is trying to look for POSTGRES_URL in the env (which is not present because I want to use prefixes for each DB depending on the environment). 2. As you can probably already guess I'm trying to make it so depending on the environment I'm using a different DB. You got any advice on that?
14 replies
DTDrizzle Team
Created by Mr Volcano on 10/18/2023 in #help
VercelPostgresError - 'missing_connection_string'
Hello everyone, so I've been beating my head with this for a couple of hours I had managed to make it work initially but after changing some things up and setting up different DBs for staging, dev and prod it is no longer working When I run npm run dev the right env variables are loaded like ( DEV_POSTGRES_URL: 'postgres://defaul... but drizzle still gives me the error in the title. My config looks like this:
const connectionString =
process.env.VERCEL_ENV === "development"
? process.env.DEV_POSTGRES_URL
: process.env.VERCEL_ENV === "production"
? process.env.PROD_POSTGRES_URL
: process.env.VERCEL_ENV === "preview"
? process.env.STAGING_POSTGRES_URL
: "";

export default {
schema: "./src/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString || ""
},
} satisfies Config;
const connectionString =
process.env.VERCEL_ENV === "development"
? process.env.DEV_POSTGRES_URL
: process.env.VERCEL_ENV === "production"
? process.env.PROD_POSTGRES_URL
: process.env.VERCEL_ENV === "preview"
? process.env.STAGING_POSTGRES_URL
: "";

export default {
schema: "./src/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString || ""
},
} satisfies Config;
But I get the same error even when I just hardcore the string. Any ideas ?
2 replies
DTDrizzle Team
Created by Mr Volcano on 8/30/2023 in #help
node-postgres uses crypto under the hood ?
Hello everyone, so I'm migrating from Prisma to Drizzle so I can use the NextJS's edge runtime I'm trying to make a query inside my edge middleware and I get the following error: The edge runtime does not support Node.js 'crypto' module. I'm using node-postgress as I've already mentioned What are my options here ?
16 replies