Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions drizzle-kit/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ export const preparePushConfig = async (
),
);
process.exit(1);
} else if (config.dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
}

assertUnreachable(config.dialect);
Expand Down Expand Up @@ -643,6 +645,8 @@ export const preparePullConfig = async (
prefix: config.migrations?.prefix || 'index',
entities: config.entities,
};
} else if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
}

assertUnreachable(dialect);
Expand Down Expand Up @@ -754,6 +758,15 @@ export const prepareStudioConfig = async (options: Record<string, unknown>) => {
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER - not a priority
return {
dialect,
schema,
host,
port,
credentials: null as any,
};
}

assertUnreachable(dialect);
Expand Down Expand Up @@ -866,6 +879,17 @@ export const prepareMigrateConfig = async (configPath: string | undefined) => {
process.exit(1);
}

if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
return {
dialect,
out,
credentials: null as any,
schema,
table,
};
}

assertUnreachable(dialect);
};

Expand Down
31 changes: 31 additions & 0 deletions drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const generate = command({
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -208,6 +210,8 @@ export const migrate = command({
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -393,6 +397,13 @@ export const push = command({
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
console.log(
error(
`You can't use 'push' command with GoogleSql dialect`,
),
);
process.exit(1);
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -464,6 +475,10 @@ export const up = command({
);
process.exit(1);
}

if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER
}
},
});

Expand Down Expand Up @@ -620,6 +635,13 @@ export const pull = command({
prefix,
entities,
);
} else if (dialect === 'googlesql') {
console.log(
error(
`You can't use 'pull' command with GoogleSql dialect`,
),
);
process.exit(1);
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -745,6 +767,13 @@ export const studio = command({
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
console.log(
error(
`You can't use 'studio' command with GoogleSql dialect`,
),
);
process.exit(1);
} else {
assertUnreachable(dialect);
}
Expand Down Expand Up @@ -847,6 +876,8 @@ export const exportRaw = command({
),
);
process.exit(1);
} else if (dialect === 'googlesql') {
throw new Error('Not implemented'); // TODO: SPANNER - probably not a priority
} else {
assertUnreachable(dialect);
}
Expand Down
65 changes: 65 additions & 0 deletions drizzle-kit/src/cli/validations/googlesql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { boolean, coerce, object, string, TypeOf, union } from 'zod';
import { error } from '../views';
import { wrapParam } from './common';
import { outputs } from './outputs';

// TODO: SPANNER - add proper credentials config

export const googlesqlCredentials = union([
object({
host: string().min(1),
port: coerce.number().min(1).optional(),
user: string().min(1).optional(),
// password: string().min(1).optional(),
// database: string().min(1),
// ssl: union([
// string(),
// object({
// pfx: string().optional(),
// key: string().optional(),
// passphrase: string().optional(),
// cert: string().optional(),
// ca: union([string(), string().array()]).optional(),
// crl: union([string(), string().array()]).optional(),
// ciphers: string().optional(),
// rejectUnauthorized: boolean().optional(),
// }),
// ]).optional(),
}),
object({
url: string().min(1),
}),
]);

export type GoogleSqlCredentials = TypeOf<typeof googlesqlCredentials>;

// TODO: SPANNER - add proper connection issues
export const printCliConnectionIssues = (options: any) => {
// const { uri, host, database } = options || {};

// if (!uri && (!host || !database)) {
// console.log(outputs.googlesql.connection.required());
// }
};

// TODO: SPANNER - add proper connection issues
export const printConfigConnectionIssues = (
options: Record<string, unknown>,
) => {
// if ('url' in options) {
// let text = `Please provide required params for MySQL driver:\n`;
// console.log(error(text));
// console.log(wrapParam('url', options.url, false, 'url'));
// process.exit(1);
// }

// let text = `Please provide required params for MySQL driver:\n`;
// console.log(error(text));
// console.log(wrapParam('host', options.host));
// console.log(wrapParam('port', options.port, true));
// console.log(wrapParam('user', options.user, true));
// console.log(wrapParam('password', options.password, true, 'secret'));
// console.log(wrapParam('database', options.database));
// console.log(wrapParam('ssl', options.ssl, true));
// process.exit(1);
};
11 changes: 10 additions & 1 deletion drizzle-kit/src/cli/validations/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const outputs = {
),
noDialect: () =>
withStyle.error(
`Please specify 'dialect' param in config, either of 'postgresql', 'mysql', 'sqlite', turso or singlestore`,
`Please specify 'dialect' param in config, either of 'postgresql', 'mysql', 'sqlite', 'googlesql', turso or singlestore`,
),
},
common: {
Expand Down Expand Up @@ -88,4 +88,13 @@ export const outputs = {
),
},
},
googlesql: {
connection: {
driver: () => withStyle.error(`Only "spanner" is available options for "--driver"`),
required: () =>
withStyle.error(
`Either "url" or "host", "database" are required for database connection`, // TODO: SPANNER - write proper error message
),
},
},
};
3 changes: 2 additions & 1 deletion drizzle-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export type Config =
})
);
}
// TODO: SPANNER - add googlesql/spanner config
);

/**
Expand All @@ -261,7 +262,7 @@ export type Config =
* **Config** usage:
*
* `dialect` - mandatory and is responsible for explicitly providing a databse dialect you are using for all the commands
* *Possible values*: `postgresql`, `mysql`, `sqlite`, `singlestore`, `gel`
* *Possible values*: `postgresql`, `mysql`, `sqlite`, `singlestore`, `gel`, `googlesql`
*
* See https://orm.drizzle.team/kit-docs/config-reference#dialect
*
Expand Down
9 changes: 9 additions & 0 deletions drizzle-kit/src/migrationPreparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ export const prepareSqliteMigrationSnapshot = async (
return { prev: prevSnapshot, cur: result, custom };
};

// TODO: SPANNER - implement
export const prepareGoogleSqlMigrationSnapshot = async (
migrationFolders: string[],
schemaPath: string | string[],
casing: CasingType | undefined,
): Promise<{ prev: MySqlSchema; cur: MySqlSchema; custom: MySqlSchema }> => {
throw new Error('Not implemented');
};

export const fillPgSnapshot = ({
serialized,
id,
Expand Down
3 changes: 2 additions & 1 deletion drizzle-kit/src/schemaValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pgSchema, pgSchemaSquashed } from './serializer/pgSchema';
import { singlestoreSchema, singlestoreSchemaSquashed } from './serializer/singlestoreSchema';
import { sqliteSchema, SQLiteSchemaSquashed } from './serializer/sqliteSchema';

export const dialects = ['postgresql', 'mysql', 'sqlite', 'turso', 'singlestore', 'gel'] as const;
export const dialects = ['postgresql', 'mysql', 'sqlite', 'turso', 'singlestore', 'gel', 'googlesql'] as const;
export const dialect = enumType(dialects);

export type Dialect = (typeof dialects)[number];
Expand All @@ -17,6 +17,7 @@ const commonSquashedSchema = union([
singlestoreSchemaSquashed,
]);

// TODO: SPANNER SCHEMA?
const commonSchema = union([pgSchema, mysqlSchema, sqliteSchema, singlestoreSchema]);

export type CommonSquashedSchema = TypeOf<typeof commonSquashedSchema>;
Expand Down
2 changes: 2 additions & 0 deletions drizzle-kit/src/sqlgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3874,6 +3874,8 @@ class SingleStoreRecreateTableConvertor extends Convertor {
}
}

// TODO: SPANNER - add googlesql/spanner classes

const convertors: Convertor[] = [];
convertors.push(new PgCreateTableConvertor());
convertors.push(new MySqlCreateTableConvertor());
Expand Down
2 changes: 2 additions & 0 deletions drizzle-kit/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ const validatorForDialect = (dialect: Dialect) => {
return { validator: backwardCompatibleSingleStoreSchema, version: 1 };
case 'gel':
return { validator: backwardCompatibleGelSchema, version: 1 };
case 'googlesql':
throw new Error('Not implemented'); // TODO: SPANNER
}
};

Expand Down
2 changes: 2 additions & 0 deletions drizzle-kit/tests/cli-generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { test as brotest } from '@drizzle-team/brocli';
import { assert, expect, test } from 'vitest';
import { generate } from '../src/cli/schema';

// TODO: SPANNER - add tests

// good:
// #1 drizzle-kit generate --dialect=postgresql --schema=schema.ts
// #2 drizzle-kit generate --dialect=postgresql --schema=schema.ts --out=out
Expand Down
2 changes: 2 additions & 0 deletions drizzle-kit/tests/cli-migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { test as brotest } from '@drizzle-team/brocli';
import { assert, expect, test } from 'vitest';
import { migrate } from '../src/cli/schema';

// TODO: SPANNER - add tests

// good:
// #1 drizzle-kit generate
// #2 drizzle-kit generate --config=turso.config.ts
Expand Down
18 changes: 17 additions & 1 deletion drizzle-orm/src/column-builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { entityKind } from '~/entity.ts';
import type { Column } from './column.ts';
import type { GelColumn, GelExtraConfigColumn } from './gel-core/index.ts';
import type { GoogleSqlColumn } from './googlesql/index.ts';
import type { MySqlColumn } from './mysql-core/index.ts';
import type { ExtraConfigColumn, PgColumn, PgSequenceOptions } from './pg-core/index.ts';
import type { SingleStoreColumn } from './singlestore-core/index.ts';
Expand All @@ -25,7 +26,7 @@ export type ColumnDataType =
| 'localDate'
| 'localDateTime';

export type Dialect = 'pg' | 'mysql' | 'sqlite' | 'singlestore' | 'common' | 'gel';
export type Dialect = 'pg' | 'mysql' | 'sqlite' | 'singlestore' | 'common' | 'gel' | 'googlesql';

export type GeneratedStorageMode = 'virtual' | 'stored';

Expand Down Expand Up @@ -325,6 +326,20 @@ export type BuildColumn<
{},
Simplify<Omit<TBuilder['_'], keyof MakeColumnConfig<TBuilder['_'], TTableName> | 'brand' | 'dialect'>>
>
: TDialect extends 'googlesql' ? GoogleSqlColumn<
MakeColumnConfig<TBuilder['_'], TTableName>,
{},
Simplify<
Omit<
TBuilder['_'],
| keyof MakeColumnConfig<TBuilder['_'], TTableName>
| 'brand'
| 'dialect'
| 'primaryKeyHasDefault'
| 'googlesqlColumnBuilderBrand'
>
>
>
: TDialect extends 'mysql' ? MySqlColumn<
MakeColumnConfig<TBuilder['_'], TTableName>,
{},
Expand Down Expand Up @@ -410,6 +425,7 @@ export type BuildExtraConfigColumns<
export type ChangeColumnTableName<TColumn extends Column, TAlias extends string, TDialect extends Dialect> =
TDialect extends 'pg' ? PgColumn<MakeColumnConfig<TColumn['_'], TAlias>>
: TDialect extends 'mysql' ? MySqlColumn<MakeColumnConfig<TColumn['_'], TAlias>>
: TDialect extends 'googlesql' ? GoogleSqlColumn<MakeColumnConfig<TColumn['_'], TAlias>>
: TDialect extends 'singlestore' ? SingleStoreColumn<MakeColumnConfig<TColumn['_'], TAlias>>
: TDialect extends 'sqlite' ? SQLiteColumn<MakeColumnConfig<TColumn['_'], TAlias>>
: TDialect extends 'gel' ? GelColumn<MakeColumnConfig<TColumn['_'], TAlias>>
Expand Down
11 changes: 11 additions & 0 deletions drizzle-orm/src/googlesql/alias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TableAliasProxyHandler } from '~/alias.ts';
import type { BuildAliasTable } from './query-builders/select.types.ts';
import type { GoogleSqlTable } from './table.ts';
import type { GoogleSqlViewBase } from './view-base.ts';

export function alias<TTable extends GoogleSqlTable | GoogleSqlViewBase, TAlias extends string>(
table: TTable,
alias: TAlias,
): BuildAliasTable<TTable, TAlias> {
return new Proxy(table, new TableAliasProxyHandler(alias, false)) as any;
}
32 changes: 32 additions & 0 deletions drizzle-orm/src/googlesql/checks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { entityKind } from '~/entity.ts';
import type { SQL } from '~/sql/sql.ts';
import type { GoogleSqlTable } from './table.ts';

export class CheckBuilder {
static readonly [entityKind]: string = 'GoogleSqlCheckBuilder';

protected brand!: 'GoogleSqlConstraintBuilder';

constructor(public name: string, public value: SQL) {}

/** @internal */
build(table: GoogleSqlTable): Check {
return new Check(table, this);
}
}

export class Check {
static readonly [entityKind]: string = 'GoogleSqlCheck';

readonly name: string;
readonly value: SQL;

constructor(public table: GoogleSqlTable, builder: CheckBuilder) {
this.name = builder.name;
this.value = builder.value;
}
}

export function check(name: string, value: SQL): CheckBuilder {
return new CheckBuilder(name, value);
}
Loading