Create database if not exists

Is there a way to have create a database if it not exists? After i create my schema and a run the first migration, i would expect drizzle to create a database that's specified in my connection string if it doesn't exist
1 Reply
Bigbill04
Bigbill049mo ago
FWIW I wrote a node script to create the database using postgresjs: reset-db.js
import postgres from 'postgres';

const psql = postgres('postgres://postgres:postgres@localhost:5432');

const resetDatabase = async () => {
await psql`drop database if exists db_name;`;
console.log('Database dropped');
await psql`create database db_name;`;
console.log('Database created');
};

await resetDatabase();

process.exit();
import postgres from 'postgres';

const psql = postgres('postgres://postgres:postgres@localhost:5432');

const resetDatabase = async () => {
await psql`drop database if exists db_name;`;
console.log('Database dropped');
await psql`create database db_name;`;
console.log('Database created');
};

await resetDatabase();

process.exit();
And I added a script to my package.json file were I call it for local development. package.json
"reset-db": "node reset-db && drizzle-kit push:pg",
"reset-db": "node reset-db && drizzle-kit push:pg",
I wanted a similar behavior as well because I was coming from Elixir's Ecto library where it handles it for you when you run mix ecto.create
Want results from more Discord servers?
Add your server