#!/usr/bin/env ts-node import { config as setupEnv } from 'dotenv-flow'; import connect from '../src/config/db'; import { main as seed } from '../src/seed'; setupEnv(); const scriptName = 'Schema Reset'; const main = async () => { const isDevelopmentLike = ['development', 'dev'].includes( process.env.NODE_ENV ?? '' ); if (!isDevelopmentLike) { throw new Error('Cannot reset schema in non-dev environment.'); } // @TODO: probably want to check for the connection host isn't foreign (e.g. // localhost and docker are ok) const db = await connect(); console.log('Dropping database...'); await db.dropDatabase(); console.log('Running migrations...'); await db.runMigrations(); // NOTE: have to close the connection since seed script opens it's own // connection. await db.close(); console.log('Running seeding scripts...'); await seed(); }; console.time(scriptName); main() .then(() => { console.timeEnd(scriptName); }) .catch((error) => { console.error(error); process.exit(1); });