Skip to content

Commit

Permalink
lint fix on drizzle-kit files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Sep 18, 2024
1 parent f86f5a1 commit a4b43df
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 36 deletions.
4 changes: 2 additions & 2 deletions drizzle-kit/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -394,7 +394,7 @@ export const generateSingleStoreMigration = async (

export const pushSingleStoreSchema = async (
imports: Record<string, unknown>,
drizzleInstance: SingleStore2Database<any>,
drizzleInstance: SingleStoreDriverDatabase<any>,
databaseName: string,
) => {
const { applySingleStoreSnapshotsDiff } = await import('./snapshotsDiffer');
Expand Down
6 changes: 5 additions & 1 deletion drizzle-kit/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 42 additions & 2 deletions drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions drizzle-kit/src/introspect-singlestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion drizzle-kit/src/migrationPreparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion drizzle-kit/src/schemaValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions drizzle-kit/src/serializer/singlestoreSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
}

Expand Down
14 changes: 0 additions & 14 deletions drizzle-kit/tests/schemaDiffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a4b43df

Please sign in to comment.