drizzle-kit export
# Edit your Drizzle schema file (e.g., schema.ts) # Make desired changes to tables, columns, indexes, etc. # Export Drizzle schema to SQL drizzle-kit export > desired-schema.sql # Plan migration pgschema plan \ --host localhost \ --db mydb \ --user postgres \ --schema public \ --file desired-schema.sql # Apply migration pgschema apply \ --host localhost \ --db mydb \ --user postgres \ --schema public \ --file desired-schema.sql
// export-full-schema.ts import { DataSource } from "typeorm"; import { entities } from "./entities"; async function exportFullSchema() { const tempDataSource = new DataSource({ type: "postgres", host: "localhost", database: "temp_db", // Use a temporary empty database synchronize: false, logging: false, entities: entities, }); await tempDataSource.initialize(); // This will generate full schema against empty db const sqlInMemory = await tempDataSource.driver .createSchemaBuilder() .log(); sqlInMemory.upQueries.forEach(query => { console.log(query.query + ";"); }); await tempDataSource.destroy(); } // Run the export exportFullSchema();
# Edit your TypeORM schema file (e.g., src/entities/xxx.ts) # Make desired changes to tables, columns, indexes, etc. # Run the export script npx ts-node export-full-schema.ts > desired-schema.sql # Plan migration pgschema plan \ --host localhost \ --db mydb \ --user postgres \ --schema public \ --file desired-schema.sql # Apply migration pgschema apply \ --host localhost \ --db mydb \ --user postgres \ --schema public \ --file desired-schema.sql