Bigbill04
Bigbill04
DTDrizzle Team
Created by Amur on 7/7/2023 in #help
Create database if not exists
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
3 replies
DTDrizzle Team
Created by Amur on 7/7/2023 in #help
Create database if not exists
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",
3 replies