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 19, 2024
1 parent f86f5a1 commit 2c57cc2
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 197 deletions.
18 changes: 14 additions & 4 deletions drizzle-kit/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
Prefix,
wrapParam,
} from '../validations/common';
import { LibSQLCredentials, libSQLCredentials, printConfigConnectionIssues as printIssuesLibSql } from '../validations/libsql';
import {
LibSQLCredentials,
libSQLCredentials,
printConfigConnectionIssues as printIssuesLibSql,
} from '../validations/libsql';
import {
MysqlCredentials,
mysqlCredentials,
Expand All @@ -28,7 +32,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 Expand Up @@ -216,7 +224,8 @@ export const preparePushConfig = async (
| {
dialect: 'turso';
credentials: LibSQLCredentials;
} | {
}
| {
dialect: 'singlestore';
credentials: SingleStoreCredentials;
}
Expand Down Expand Up @@ -404,7 +413,8 @@ export const preparePullConfig = async (
| {
dialect: 'turso';
credentials: LibSQLCredentials;
} | {
}
| {
dialect: 'singlestore';
credentials: SingleStoreCredentials;
}
Expand Down
2 changes: 1 addition & 1 deletion drizzle-kit/src/cli/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export const connectToLibSQL = async (credentials: LibSQLCredentials): Promise<
"Please install '@libsql/client' for Drizzle Kit to connect to LibSQL databases",
);
process.exit(1);
}
};

const parseSingleStoreCredentials = (credentials: SingleStoreCredentials) => {
if ('url' in credentials) {
Expand Down
41 changes: 40 additions & 1 deletion drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ 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 { prepareAndMigrateSingleStore } from './commands/migrate';
import { grey, MigrateProgress } from './views';

const optionDialect = string('dialect')
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,6 +342,16 @@ export const push = command({
tablesFilter,
force,
);
} else if (dialect === 'singlestore') {
const { singlestorePush } = await import('./commands/push');
await singlestorePush(
schemaPath,
credentials,
tablesFilter,
strict,
verbose,
force,
);
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -517,6 +541,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 +656,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
6 changes: 4 additions & 2 deletions drizzle-kit/src/jsonStatements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { MySqlKitInternals, MySqlSchema, MySqlSquasher } from './serializer/mysq
import { Index, PgSchema, PgSquasher } from './serializer/pgSchema';
import { SingleStoreKitInternals, SingleStoreSchema, SingleStoreSquasher } from './serializer/singlestoreSchema';
import {
SQLiteKitInternals, SQLiteSchemaInternal,
SQLiteSchemaSquashed, SQLiteSquasher
SQLiteKitInternals,
SQLiteSchemaInternal,
SQLiteSchemaSquashed,
SQLiteSquasher,
} from './serializer/sqliteSchema';
import { AlteredColumn, Column, Sequence, Table } from './snapshotsDiffer';

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
20 changes: 10 additions & 10 deletions drizzle-kit/src/serializer/singlestoreSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { RowDataPacket } from 'mysql2/promise';
import { withStyle } from '../cli/validations/outputs';
import { IntrospectStage, IntrospectStatus } from '../cli/views';

import { sqlToStr } from '.';
import type { DB } from '../utils';
import { sqlToStr } from '.';
import {
Column,
Index,
Expand Down 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
10 changes: 5 additions & 5 deletions drizzle-kit/src/serializer/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
Relations,
TablesRelationalConfig,
} from 'drizzle-orm';
import { AnyMySqlTable, MySqlTable, getTableConfig as mysqlTableConfig } from 'drizzle-orm/mysql-core';
import { AnyPgTable, PgTable, getTableConfig as pgTableConfig } from 'drizzle-orm/pg-core';
import { AnyMySqlTable, getTableConfig as mysqlTableConfig, MySqlTable } from 'drizzle-orm/mysql-core';
import { AnyPgTable, getTableConfig as pgTableConfig, PgTable } from 'drizzle-orm/pg-core';
import {
AnySingleStoreTable,
SingleStoreTable,
getTableConfig as singlestoreTableConfig,
SingleStoreTable,
} from 'drizzle-orm/singlestore-core';
import { AnySQLiteTable, SQLiteTable, getTableConfig as sqliteTableConfig } from 'drizzle-orm/sqlite-core';
import { AnySQLiteTable, getTableConfig as sqliteTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
import fs from 'fs';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
Expand All @@ -29,12 +29,12 @@ import { LibSQLCredentials } from 'src/cli/validations/libsql';
import { assertUnreachable } from 'src/global';
import superjson from 'superjson';
import { z } from 'zod';
import { prepareFilenames } from '.';
import { safeRegister } from '../cli/commands/utils';
import type { MysqlCredentials } from '../cli/validations/mysql';
import type { PostgresCredentials } from '../cli/validations/postgres';
import type { SingleStoreCredentials } from '../cli/validations/singlestore';
import type { SqliteCredentials } from '../cli/validations/sqlite';
import { prepareFilenames } from '.';

type CustomDefault = {
schema: string;
Expand Down
4 changes: 2 additions & 2 deletions drizzle-kit/src/snapshotsDiffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
string,
TypeOf,
union,
ZodTypeAny
ZodTypeAny,
} from 'zod';
import { applyJsonDiff, diffColumns, diffSchemasOrTables } from './jsonDiffer';
import { fromJson } from './sqlgenerator';
Expand Down Expand Up @@ -56,11 +56,11 @@ import {
prepareDeleteCompositePrimaryKeyPg,
prepareDeleteCompositePrimaryKeySingleStore,
prepareDeleteCompositePrimaryKeySqlite,
prepareDeleteSchemasJson as prepareDropSchemasJson,
prepareDeleteUniqueConstraintPg as prepareDeleteUniqueConstraint,
prepareDropEnumJson,
prepareDropIndexesJson,
prepareDropReferencesJson,
prepareDeleteSchemasJson as prepareDropSchemasJson,
prepareDropSequenceJson,
prepareDropTableJson,
prepareLibSQLCreateReferencesJson,
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
Loading

0 comments on commit 2c57cc2

Please sign in to comment.