From a4b43dfb4dafeb6b3611504d77e92d8afd007339 Mon Sep 17 00:00:00 2001 From: prodrigues Date: Tue, 13 Aug 2024 11:20:06 +0100 Subject: [PATCH] lint fix on drizzle-kit files --- drizzle-kit/src/api.ts | 4 +- drizzle-kit/src/cli/commands/utils.ts | 6 ++- drizzle-kit/src/cli/schema.ts | 44 ++++++++++++++++++- drizzle-kit/src/introspect-singlestore.ts | 11 +++-- drizzle-kit/src/migrationPreparator.ts | 1 - drizzle-kit/src/schemaValidator.ts | 1 - .../src/serializer/singlestoreSerializer.ts | 18 ++++---- drizzle-kit/tests/schemaDiffer.ts | 14 ------ 8 files changed, 63 insertions(+), 36 deletions(-) diff --git a/drizzle-kit/src/api.ts b/drizzle-kit/src/api.ts index 2ac44f5b7..3922da088 100644 --- a/drizzle-kit/src/api.ts +++ b/drizzle-kit/src/api.ts @@ -2,7 +2,7 @@ import { randomUUID } from 'crypto'; import { LibSQLDatabase } from 'drizzle-orm/libsql'; import type { MySql2Database } from 'drizzle-orm/mysql2'; import { PgDatabase } from 'drizzle-orm/pg-core'; -import { SingleStore2Database } from 'drizzle-orm/singlestore'; +import { SingleStoreDriverDatabase } from 'drizzle-orm/singlestore'; import { columnsResolver, enumsResolver, @@ -394,7 +394,7 @@ export const generateSingleStoreMigration = async ( export const pushSingleStoreSchema = async ( imports: Record, - drizzleInstance: SingleStore2Database, + drizzleInstance: SingleStoreDriverDatabase, databaseName: string, ) => { const { applySingleStoreSnapshotsDiff } = await import('./snapshotsDiffer'); diff --git a/drizzle-kit/src/cli/commands/utils.ts b/drizzle-kit/src/cli/commands/utils.ts index d80b736fe..8de7f3319 100644 --- a/drizzle-kit/src/cli/commands/utils.ts +++ b/drizzle-kit/src/cli/commands/utils.ts @@ -28,7 +28,11 @@ import { postgresCredentials, printConfigConnectionIssues as printIssuesPg, } from '../validations/postgres'; -import { printConfigConnectionIssues as printIssuesSingleStore, singlestoreCredentials, SingleStoreCredentials } from '../validations/singlestore'; +import { + printConfigConnectionIssues as printIssuesSingleStore, + SingleStoreCredentials, + singlestoreCredentials, +} from '../validations/singlestore'; import { printConfigConnectionIssues as printIssuesSqlite, SqliteCredentials, diff --git a/drizzle-kit/src/cli/schema.ts b/drizzle-kit/src/cli/schema.ts index c7d5b88f3..89b9ebf88 100644 --- a/drizzle-kit/src/cli/schema.ts +++ b/drizzle-kit/src/cli/schema.ts @@ -24,9 +24,10 @@ import { mkdirSync } from 'fs'; import { renderWithTask } from 'hanji'; import { dialects } from 'src/schemaValidator'; import { assertUnreachable } from '../global'; -import { drizzleForLibSQL, type Setup } from '../serializer/studio'; +import { drizzleForLibSQL, drizzleForSingleStore, prepareSingleStoreSchema, type Setup } from '../serializer/studio'; import { certs } from '../utils/certs'; import { grey, MigrateProgress } from './views'; +import { prepareAndMigrateSingleStore } from './commands/migrate'; const optionDialect = string('dialect') .enum(...dialects) @@ -89,6 +90,8 @@ export const generate = command({ await prepareAndMigrateSqlite(opts); } else if (dialect === 'turso') { await prepareAndMigrateLibSQL(opts); + } else if (dialect === 'singlestore') { + await prepareAndMigrateSingleStore(opts); } else { assertUnreachable(dialect); } @@ -173,6 +176,17 @@ export const migrate = command({ migrationsSchema: schema, }), ); + } else if (dialect === 'singlestore') { + const { connectToSingleStore } = await import('./connections'); + const { migrate } = await connectToSingleStore(credentials); + await renderWithTask( + new MigrateProgress(), + migrate({ + migrationsFolder: out, + migrationsTable: table, + migrationsSchema: schema, + }), + ); } else { assertUnreachable(dialect); } @@ -328,7 +342,18 @@ export const push = command({ tablesFilter, force, ); - } else { + } else if (dialect === 'singlestore') { + const { singlestorePush } = await import('./commands/push'); + await singlestorePush( + schemaPath, + credentials, + tablesFilter, + strict, + verbose, + force, + ); + } + else { assertUnreachable(dialect); } } catch (e) { @@ -517,6 +542,16 @@ export const pull = command({ tablesFilter, prefix, ); + } else if (dialect === 'singlestore') { + const { introspectSingleStore } = await import('./commands/introspect'); + await introspectSingleStore( + casing, + out, + breakpoints, + credentials, + tablesFilter, + prefix, + ); } else { assertUnreachable(dialect); } @@ -622,6 +657,11 @@ export const studio = command({ ? await prepareSQLiteSchema(schemaPath) : { schema: {}, relations: {}, files: [] }; setup = await drizzleForLibSQL(credentials, schema, relations, files); + } else if (dialect === 'singlestore') { + const { schema, relations, files } = schemaPath + ? await prepareSingleStoreSchema(schemaPath) + : { schema: {}, relations: {}, files: [] }; + setup = await drizzleForSingleStore(credentials, schema, relations, files); } else { assertUnreachable(dialect); } diff --git a/drizzle-kit/src/introspect-singlestore.ts b/drizzle-kit/src/introspect-singlestore.ts index b9efc537a..8aa6e3dd7 100644 --- a/drizzle-kit/src/introspect-singlestore.ts +++ b/drizzle-kit/src/introspect-singlestore.ts @@ -386,16 +386,15 @@ const column = ( ? `${casing(name)}: timestamp("${name}", ${params})` : `${casing(name)}: timestamp("${name}")`; - - // TODO: check if SingleStore has defaultNow() or now() - defaultValue = defaultValue === 'now()' || defaultValue === '(CURRENT_TIMESTAMP)' + // TODO: check if SingleStore has defaultNow() or now() + defaultValue = defaultValue === 'now()' || defaultValue === '(CURRENT_TIMESTAMP)' ? '.defaultNow()' : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : ''; - - out += defaultValue; - + + out += defaultValue; + // TODO: check if SingleStore has onUpdateNow() let onUpdateNow = onUpdate ? '.onUpdateNow()' : ''; out += onUpdateNow; diff --git a/drizzle-kit/src/migrationPreparator.ts b/drizzle-kit/src/migrationPreparator.ts index 3d1ddbea3..4e5664290 100644 --- a/drizzle-kit/src/migrationPreparator.ts +++ b/drizzle-kit/src/migrationPreparator.ts @@ -5,7 +5,6 @@ import { dryMySql, MySqlSchema, mysqlSchema } from './serializer/mysqlSchema'; import { dryPg, PgSchema, pgSchema, PgSchemaInternal } from './serializer/pgSchema'; import { drySingleStore, SingleStoreSchema, singlestoreSchema } from './serializer/singlestoreSchema'; import { drySQLite, SQLiteSchema, sqliteSchema } from './serializer/sqliteSchema'; -import { drySingleStore, singlestoreSchema, SingleStoreSchema } from './serializer/singlestoreSchema'; export const prepareMySqlDbPushSnapshot = async ( prev: MySqlSchema, diff --git a/drizzle-kit/src/schemaValidator.ts b/drizzle-kit/src/schemaValidator.ts index 4065e948f..e91b5ab11 100644 --- a/drizzle-kit/src/schemaValidator.ts +++ b/drizzle-kit/src/schemaValidator.ts @@ -3,7 +3,6 @@ import { mysqlSchema, mysqlSchemaSquashed } from './serializer/mysqlSchema'; import { pgSchema, pgSchemaSquashed } from './serializer/pgSchema'; import { singlestoreSchema, singlestoreSchemaSquashed } from './serializer/singlestoreSchema'; import { sqliteSchema, SQLiteSchemaSquashed } from './serializer/sqliteSchema'; -import { singlestoreSchema, singlestoreSchemaSquashed } from './serializer/singlestoreSchema'; export const dialects = ['postgresql', 'mysql', 'sqlite', 'turso', 'singlestore'] as const; export const dialect = enumType(dialects); diff --git a/drizzle-kit/src/serializer/singlestoreSerializer.ts b/drizzle-kit/src/serializer/singlestoreSerializer.ts index 3f36f9c21..1aca03037 100644 --- a/drizzle-kit/src/serializer/singlestoreSerializer.ts +++ b/drizzle-kit/src/serializer/singlestoreSerializer.ts @@ -573,15 +573,15 @@ export const fromDatabase = async ( }; } } else { - if (typeof tableInResult.indexes[constraintName] !== 'undefined') { - tableInResult.indexes[constraintName]!.columns.push(columnName); - } else { - tableInResult.indexes[constraintName] = { - name: constraintName, - columns: [columnName], - isUnique: isUnique, - }; - } + if (typeof tableInResult.indexes[constraintName] !== 'undefined') { + tableInResult.indexes[constraintName]!.columns.push(columnName); + } else { + tableInResult.indexes[constraintName] = { + name: constraintName, + columns: [columnName], + isUnique: isUnique, + }; + } } } diff --git a/drizzle-kit/tests/schemaDiffer.ts b/drizzle-kit/tests/schemaDiffer.ts index da16dac87..3223ca5e7 100644 --- a/drizzle-kit/tests/schemaDiffer.ts +++ b/drizzle-kit/tests/schemaDiffer.ts @@ -1099,13 +1099,6 @@ export async function diffTestSchemasPushLibSQL( run: async (query: string) => { await client.execute(query); }, - batch: async ( - queries: { query: string; values?: any[] | undefined }[], - ) => { - await client.batch( - queries.map((it) => ({ sql: it.query, args: it.values ?? [] })), - ); - }, }, undefined, ); @@ -1165,13 +1158,6 @@ export async function diffTestSchemasPushLibSQL( run: async (query: string) => { await client.execute(query); }, - batch: async ( - queries: { query: string; values?: any[] | undefined }[], - ) => { - await client.batch( - queries.map((it) => ({ sql: it.query, args: it.values ?? [] })), - ); - }, }, statements, sn1,