Skip to content

Commit

Permalink
added export for singlestore
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrSherman committed Dec 11, 2024
1 parent 77a981a commit 6743980
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
32 changes: 32 additions & 0 deletions drizzle-kit/src/cli/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,38 @@ export const prepareAndMigrateSingleStore = async (config: GenerateConfig) => {
}
};

export const prepareAndExportSinglestore = async (config: ExportConfig) => {
const schemaPath = config.schema;

try {
const { prev, cur } = await prepareSingleStoreMigrationSnapshot(
[],
schemaPath,
undefined,
);

const validatedPrev = singlestoreSchema.parse(prev);
const validatedCur = singlestoreSchema.parse(cur);

const squashedPrev = squashSingleStoreScheme(validatedPrev);
const squashedCur = squashSingleStoreScheme(validatedCur);

const { sqlStatements, _meta } = await applySingleStoreSnapshotsDiff(
squashedPrev,
squashedCur,
tablesResolver,
columnsResolver,
/* singleStoreViewsResolver, */
validatedPrev,
validatedCur,
);

console.log(sqlStatements.join('\n'));
} catch (e) {
console.error(e);
}
};

export const prepareAndExportMysql = async (config: ExportConfig) => {
const schemaPath = config.schema;

Expand Down
10 changes: 8 additions & 2 deletions drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,13 @@ export const exportRaw = command({
await assertOrmCoreVersion();
await assertPackages('drizzle-orm');

const { prepareAndExportPg, prepareAndExportMysql, prepareAndExportSqlite, prepareAndExportLibSQL } = await import(
const {
prepareAndExportPg,
prepareAndExportMysql,
prepareAndExportSqlite,
prepareAndExportLibSQL,
prepareAndExportSinglestore,
} = await import(
'./commands/migrate'
);

Expand All @@ -780,7 +786,7 @@ export const exportRaw = command({
} else if (dialect === 'turso') {
await prepareAndExportLibSQL(opts);
} else if (dialect === 'singlestore') {
await prepareAndExportSqlite(opts);
await prepareAndExportSinglestore(opts);
} else {
assertUnreachable(dialect);
}
Expand Down
6 changes: 3 additions & 3 deletions drizzle-kit/tests/cli-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { exportRaw } from '../src/cli/schema';
// #4 drizzle-kit export --config=drizzle.config.ts --schema=schema.ts
// #5 drizzle-kit export --config=drizzle.config.ts --dialect=postgresql

test('exportRaw #1', async (t) => {
test('export #1', async (t) => {
const res = await brotest(
exportRaw,
'--dialect=postgresql --schema=schema.ts',
Expand All @@ -29,7 +29,7 @@ test('exportRaw #1', async (t) => {
});
});

test('exportRaw #2', async (t) => {
test('export #2', async (t) => {
const res = await brotest(exportRaw, '');

if (res.type !== 'handler') assert.fail(res.type, 'handler');
Expand All @@ -41,7 +41,7 @@ test('exportRaw #2', async (t) => {
});

// custom config path
test('exportRaw #3', async (t) => {
test('export #3', async (t) => {
const res = await brotest(exportRaw, '--config=expo.config.ts');
assert.equal(res.type, 'handler');
if (res.type !== 'handler') assert.fail(res.type, 'handler');
Expand Down

0 comments on commit 6743980

Please sign in to comment.