@@ -54,7 +54,7 @@ import {
5454 ResolveSelectNamed ,
5555 schema ,
5656} from '../views' ;
57- import { GenerateConfig } from './utils' ;
57+ import { ExportConfig , GenerateConfig } from './utils' ;
5858
5959export type Named = {
6060 name : string ;
@@ -368,6 +368,44 @@ export const prepareAndMigratePg = async (config: GenerateConfig) => {
368368 }
369369} ;
370370
371+ export const prepareAndExportPg = async ( config : ExportConfig ) => {
372+ const schemaPath = config . schema ;
373+
374+ try {
375+ const { prev, cur } = await preparePgMigrationSnapshot (
376+ [ ] , // no snapshots before
377+ schemaPath ,
378+ undefined ,
379+ ) ;
380+
381+ const validatedPrev = pgSchema . parse ( prev ) ;
382+ const validatedCur = pgSchema . parse ( cur ) ;
383+
384+ const squashedPrev = squashPgScheme ( validatedPrev ) ;
385+ const squashedCur = squashPgScheme ( validatedCur ) ;
386+
387+ const { sqlStatements } = await applyPgSnapshotsDiff (
388+ squashedPrev ,
389+ squashedCur ,
390+ schemasResolver ,
391+ enumsResolver ,
392+ sequencesResolver ,
393+ policyResolver ,
394+ indPolicyResolver ,
395+ roleResolver ,
396+ tablesResolver ,
397+ columnsResolver ,
398+ viewsResolver ,
399+ validatedPrev ,
400+ validatedCur ,
401+ ) ;
402+
403+ console . log ( sqlStatements . join ( '\n' ) ) ;
404+ } catch ( e ) {
405+ console . error ( e ) ;
406+ }
407+ } ;
408+
371409export const preparePgPush = async (
372410 cur : PgSchema ,
373411 prev : PgSchema ,
@@ -697,6 +735,70 @@ export const prepareAndMigrateSingleStore = async (config: GenerateConfig) => {
697735 }
698736} ;
699737
738+ export const prepareAndExportSinglestore = async ( config : ExportConfig ) => {
739+ const schemaPath = config . schema ;
740+
741+ try {
742+ const { prev, cur } = await prepareSingleStoreMigrationSnapshot (
743+ [ ] ,
744+ schemaPath ,
745+ undefined ,
746+ ) ;
747+
748+ const validatedPrev = singlestoreSchema . parse ( prev ) ;
749+ const validatedCur = singlestoreSchema . parse ( cur ) ;
750+
751+ const squashedPrev = squashSingleStoreScheme ( validatedPrev ) ;
752+ const squashedCur = squashSingleStoreScheme ( validatedCur ) ;
753+
754+ const { sqlStatements, _meta } = await applySingleStoreSnapshotsDiff (
755+ squashedPrev ,
756+ squashedCur ,
757+ tablesResolver ,
758+ columnsResolver ,
759+ /* singleStoreViewsResolver, */
760+ validatedPrev ,
761+ validatedCur ,
762+ ) ;
763+
764+ console . log ( sqlStatements . join ( '\n' ) ) ;
765+ } catch ( e ) {
766+ console . error ( e ) ;
767+ }
768+ } ;
769+
770+ export const prepareAndExportMysql = async ( config : ExportConfig ) => {
771+ const schemaPath = config . schema ;
772+
773+ try {
774+ const { prev, cur, custom } = await prepareMySqlMigrationSnapshot (
775+ [ ] ,
776+ schemaPath ,
777+ undefined ,
778+ ) ;
779+
780+ const validatedPrev = mysqlSchema . parse ( prev ) ;
781+ const validatedCur = mysqlSchema . parse ( cur ) ;
782+
783+ const squashedPrev = squashMysqlScheme ( validatedPrev ) ;
784+ const squashedCur = squashMysqlScheme ( validatedCur ) ;
785+
786+ const { sqlStatements, statements, _meta } = await applyMysqlSnapshotsDiff (
787+ squashedPrev ,
788+ squashedCur ,
789+ tablesResolver ,
790+ columnsResolver ,
791+ mySqlViewsResolver ,
792+ validatedPrev ,
793+ validatedCur ,
794+ ) ;
795+
796+ console . log ( sqlStatements . join ( '\n' ) ) ;
797+ } catch ( e ) {
798+ console . error ( e ) ;
799+ }
800+ } ;
801+
700802export const prepareAndMigrateSqlite = async ( config : GenerateConfig ) => {
701803 const outFolder = config . out ;
702804 const schemaPath = config . schema ;
@@ -760,6 +862,38 @@ export const prepareAndMigrateSqlite = async (config: GenerateConfig) => {
760862 }
761863} ;
762864
865+ export const prepareAndExportSqlite = async ( config : ExportConfig ) => {
866+ const schemaPath = config . schema ;
867+
868+ try {
869+ const { prev, cur } = await prepareSqliteMigrationSnapshot (
870+ [ ] ,
871+ schemaPath ,
872+ undefined ,
873+ ) ;
874+
875+ const validatedPrev = sqliteSchema . parse ( prev ) ;
876+ const validatedCur = sqliteSchema . parse ( cur ) ;
877+
878+ const squashedPrev = squashSqliteScheme ( validatedPrev ) ;
879+ const squashedCur = squashSqliteScheme ( validatedCur ) ;
880+
881+ const { sqlStatements, _meta } = await applySqliteSnapshotsDiff (
882+ squashedPrev ,
883+ squashedCur ,
884+ tablesResolver ,
885+ columnsResolver ,
886+ sqliteViewsResolver ,
887+ validatedPrev ,
888+ validatedCur ,
889+ ) ;
890+
891+ console . log ( sqlStatements . join ( '\n' ) ) ;
892+ } catch ( e ) {
893+ console . error ( e ) ;
894+ }
895+ } ;
896+
763897export const prepareAndMigrateLibSQL = async ( config : GenerateConfig ) => {
764898 const outFolder = config . out ;
765899 const schemaPath = config . schema ;
@@ -822,6 +956,38 @@ export const prepareAndMigrateLibSQL = async (config: GenerateConfig) => {
822956 }
823957} ;
824958
959+ export const prepareAndExportLibSQL = async ( config : ExportConfig ) => {
960+ const schemaPath = config . schema ;
961+
962+ try {
963+ const { prev, cur, custom } = await prepareSqliteMigrationSnapshot (
964+ [ ] ,
965+ schemaPath ,
966+ undefined ,
967+ ) ;
968+
969+ const validatedPrev = sqliteSchema . parse ( prev ) ;
970+ const validatedCur = sqliteSchema . parse ( cur ) ;
971+
972+ const squashedPrev = squashSqliteScheme ( validatedPrev ) ;
973+ const squashedCur = squashSqliteScheme ( validatedCur ) ;
974+
975+ const { sqlStatements, _meta } = await applyLibSQLSnapshotsDiff (
976+ squashedPrev ,
977+ squashedCur ,
978+ tablesResolver ,
979+ columnsResolver ,
980+ sqliteViewsResolver ,
981+ validatedPrev ,
982+ validatedCur ,
983+ ) ;
984+
985+ console . log ( sqlStatements . join ( '\n' ) ) ;
986+ } catch ( e ) {
987+ console . error ( e ) ;
988+ }
989+ } ;
990+
825991export const prepareSQLitePush = async (
826992 schemaPath : string | string [ ] ,
827993 snapshot : SQLiteSchema ,
0 commit comments