Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d5f2f38
[MsSql] initial implementation
Angelelz Dec 4, 2023
2408d08
[MsSql] deleted deprecated methods and functions and fixed types for …
Angelelz Dec 4, 2023
322d93e
[MsSql] Delete serial data type and added identity to number data types
Angelelz Dec 4, 2023
6b82886
[MsSql] Added mssql and @types/mssql to integration tests package
Angelelz Dec 4, 2023
bfe701a
[MsSql] Removed intersectAll and exceptAll
Angelelz Dec 4, 2023
a276cd6
[MsSql] Added a way to not insert default on identity columns
Angelelz Dec 4, 2023
fa066f0
[MsSql][teporary] made json column be a text
Angelelz Dec 4, 2023
e460cae
[MsSql] datetime columns don't need to be mapped to a Date object mss…
Angelelz Dec 4, 2023
cc17337
[MsSql] fix offset and fetch in select and allow insert default values
Angelelz Dec 6, 2023
8a78552
[MsSql] Fix save transaction syntax
Angelelz Dec 6, 2023
30e8388
[MsSql] Added limit and offset to select
Angelelz Dec 6, 2023
4537f30
[MsSql] deleted not supported onDuplicateKey
Angelelz Dec 6, 2023
ae1ee89
[MsSql] Removed unsopported ignore in insert
Angelelz Dec 6, 2023
1e21efe
[MsSql] Fixed syntax in migrate function
Angelelz Dec 6, 2023
5eb62fb
[MsSql] Fixed integer columns and deleted not used types
Angelelz Dec 6, 2023
a584000
[MsSql] Created but data type
Angelelz Dec 6, 2023
abb7dc4
[MsSql] Fixed string data types
Angelelz Dec 6, 2023
7b0d51d
[MsSql] fixed time data types
Angelelz Dec 6, 2023
d6e9aa0
[MsSql] Added initial batch of integration tests
Angelelz Dec 6, 2023
b828b7f
[MsSql] Made config for char and varchar optional
Angelelz Dec 9, 2023
08dea00
[MsSql] Added dialect support for top and for clauses in the select
Angelelz Dec 9, 2023
d8c6ce3
[MsSql] [feat] Added RQB support
Angelelz Dec 9, 2023
96469fa
[MsSql] Added schema and RQB tests
Angelelz Dec 9, 2023
162014a
possible tests fix
Angelelz Dec 9, 2023
1b85030
Revert "possible tests fix"
Angelelz Dec 9, 2023
15c2736
[All] Added types and new config option to column and column-builder …
Angelelz Nov 14, 2023
3ce2ce4
[MySql] Added implementation for dialect
Angelelz Nov 14, 2023
66b2064
[Pg] Added implementation for dialect
Angelelz Nov 14, 2023
c217d67
[SQLite] Added implementation for dialect
Angelelz Nov 14, 2023
6e645fc
[All] Improved performance of update builder in the dialect
Angelelz Nov 17, 2023
eeff784
[All] Fixed insert and update behavior
Angelelz Nov 19, 2023
a1e1d20
[All] Added integration tests
Angelelz Nov 19, 2023
eee4a7c
[All] Added requested changes: fix issue ignoring null values on update
Angelelz Nov 24, 2023
fca2a10
[MsSql] Added support for `$onUpdate` and added tests
Angelelz Dec 9, 2023
6a851a8
[MsSql] Allmost all columns and column features supported
Angelelz Dec 10, 2023
3250b98
fixed integration tests types
Angelelz Dec 10, 2023
1501075
[MsSql] Added types tests
Angelelz Dec 10, 2023
122aba1
[All] Added types for generated columns and fix insert and update typ…
Angelelz Dec 11, 2023
dff0b62
[All] Fixed types tests with the new generated columns types
Angelelz Dec 11, 2023
2593029
[MsSql] Added schema tests
Angelelz Dec 11, 2023
b63ee6f
[MsSql] Added prefixed tests
Angelelz Dec 11, 2023
08ee135
[MsSql] Added tests for custom types
Angelelz Dec 12, 2023
8c5a652
[MsSql] Added tests for replicas and fixed types
Angelelz Dec 12, 2023
0b50a5a
[MsSql] Improve the types for db.execute. It properly returns the typ…
Angelelz Dec 12, 2023
7ba7903
[MsSql] fix: use schema name in select when the table is aliased
Angelelz Jan 11, 2024
ba75278
Merge branch 'master' into internal-mssql
Angelelz Oct 22, 2024
551ef75
fix type and linting errors
Angelelz Oct 22, 2024
cf27019
fixed all conflicts but having circular dependency issues
Angelelz Oct 26, 2024
84f3e4d
fix circular deps and moved mssql test to vitest
Angelelz Oct 27, 2024
0321ace
fixed type error in tests
Angelelz Oct 27, 2024
ec26cc8
Merge branch 'beta' of github.com:drizzle-team/drizzle-orm into feat-…
AndriiSherman Jan 9, 2025
97273ad
Fix build error
AndriiSherman Jan 9, 2025
2b4d71a
Updated:
ProvorovOleksii Apr 16, 2025
ce6270c
merge main to feat-mssql-support
AleksandrSherman Apr 17, 2025
9672402
casing + data types + joins tests
AleksandrSherman Apr 22, 2025
ed3317f
Fixed type errors in test for mssql
AleksandrSherman Apr 22, 2025
9c08781
WIP limit offset
AleksandrSherman Apr 23, 2025
99d6b2b
WIP limit offset
AleksandrSherman Apr 23, 2025
41dde7a
[mssql] mandatory constraint names + tests
AleksandrSherman Apr 24, 2025
2ddac33
Merge branch 'main' of https://github.com/drizzle-team/drizzle-orm in…
AleksandrSherman Apr 24, 2025
66b0a84
[mssql]: fixed tests
AleksandrSherman Apr 24, 2025
57a3967
[mssql]: fixed deps
AleksandrSherman Apr 24, 2025
e653aa9
Merge branch 'main' of https://github.com/drizzle-team/drizzle-orm in…
AleksandrSherman Apr 24, 2025
96704d0
[mssql] constraint names are not mandatory now
AleksandrSherman Apr 25, 2025
4431f64
[mssql] commented drizzle-kit logic
AleksandrSherman Apr 25, 2025
7040e8e
Merge branch 'main' of https://github.com/drizzle-team/drizzle-orm in…
AleksandrSherman Apr 25, 2025
47c6ad4
[mssql]: fixed imports
AleksandrSherman Apr 25, 2025
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
2 changes: 2 additions & 0 deletions drizzle-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@types/json-diff": "^1.0.3",
"@types/micromatch": "^4.0.9",
"@types/minimatch": "^5.1.2",
"@types/mssql": "^9.1.4",
"@types/node": "^18.11.15",
"@types/pg": "^8.10.7",
"@types/pluralize": "^0.0.33",
Expand Down Expand Up @@ -97,6 +98,7 @@
"json-diff": "1.0.6",
"micromatch": "^4.0.8",
"minimatch": "^7.4.3",
"mssql": "^10.0.1",
"mysql2": "3.3.3",
"node-fetch": "^3.3.2",
"ohm-js": "^17.1.0",
Expand Down
115 changes: 115 additions & 0 deletions drizzle-kit/src/cli/commands/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Minimatch } from 'minimatch';
import { join } from 'path';
import { plural, singular } from 'pluralize';
import { GelSchema } from 'src/serializer/gelSchema';
import { dryMsSql, MsSqlSchema, squashMssqlScheme } from 'src/serializer/mssqlSchema';
import { drySingleStore, SingleStoreSchema, squashSingleStoreScheme } from 'src/serializer/singlestoreSchema';
import { assertUnreachable, originUUID } from '../../global';
import { schemaToTypeScript as gelSchemaToTypeScript } from '../../introspect-gel';
Expand All @@ -13,6 +14,7 @@ import { paramNameFor, schemaToTypeScript as postgresSchemaToTypeScript } from '
import { schemaToTypeScript as singlestoreSchemaToTypeScript } from '../../introspect-singlestore';
import { schemaToTypeScript as sqliteSchemaToTypeScript } from '../../introspect-sqlite';
import { fromDatabase as fromGelDatabase } from '../../serializer/gelSerializer';
import { fromDatabase as fromMssqlDatabase } from '../../serializer/mssqlSerializer';
import { dryMySql, MySqlSchema, squashMysqlScheme } from '../../serializer/mysqlSchema';
import { fromDatabase as fromMysqlDatabase } from '../../serializer/mysqlSerializer';
import { dryPg, type PgSchema, squashPgScheme } from '../../serializer/pgSchema';
Expand All @@ -22,6 +24,7 @@ import { drySQLite, type SQLiteSchema, squashSqliteScheme } from '../../serializ
import { fromDatabase as fromSqliteDatabase } from '../../serializer/sqliteSerializer';
import {
applyLibSQLSnapshotsDiff,
applyMssqlSnapshotsDiff,
applyMysqlSnapshotsDiff,
applyPgSnapshotsDiff,
applySingleStoreSnapshotsDiff,
Expand All @@ -32,6 +35,7 @@ import { Entities } from '../validations/cli';
import type { Casing, Prefix } from '../validations/common';
import { GelCredentials } from '../validations/gel';
import { LibSQLCredentials } from '../validations/libsql';
import { MssqlCredentials } from '../validations/mssql';
import type { MysqlCredentials } from '../validations/mysql';
import type { PostgresCredentials } from '../validations/postgres';
import { SingleStoreCredentials } from '../validations/singlestore';
Expand Down Expand Up @@ -415,6 +419,117 @@ export const introspectMysql = async (
process.exit(0);
};

// export const introspectMssql = async (
// casing: Casing,
// out: string,
// breakpoints: boolean,
// credentials: MssqlCredentials,
// tablesFilter: string[],
// prefix: Prefix,
// ) => {
// const { connectToMsSQL } = await import('../connections');
// const { db, database } = await connectToMsSQL(credentials);

// const matchers = tablesFilter.map((it) => {
// return new Minimatch(it);
// });

// const filter = (tableName: string) => {
// if (matchers.length === 0) return true;

// let flags: boolean[] = [];

// for (let matcher of matchers) {
// if (matcher.negate) {
// if (!matcher.match(tableName)) {
// flags.push(false);
// }
// }

// if (matcher.match(tableName)) {
// flags.push(true);
// }
// }

// if (flags.length > 0) {
// return flags.every(Boolean);
// }
// return false;
// };

// const progress = new IntrospectProgress();
// const res = await renderWithTask(
// progress,
// fromMssqlDatabase(db, database, filter, (stage, count, status) => {
// progress.update(stage, count, status);
// }),
// );

// const schema = { id: originUUID, prevId: '', ...res } as MsSqlSchema;
// const ts = mssqlSchemaToTypeScript(schema, casing);
// const relationsTs = relationsToTypeScript(schema, casing);
// const { internal, ...schemaWithoutInternals } = schema;

// const schemaFile = join(out, 'schema.ts');
// writeFileSync(schemaFile, ts.file);
// const relationsFile = join(out, 'relations.ts');
// writeFileSync(relationsFile, relationsTs.file);
// console.log();

// const { snapshots, journal } = prepareOutFolder(out, 'mysql');

// if (snapshots.length === 0) {
// const { sqlStatements, _meta } = await applyMssqlSnapshotsDiff(
// squashMssqlScheme(dryMsSql),
// squashMssqlScheme(schema),
// tablesResolver,
// columnsResolver,
// mySqlViewsResolver,
// dryMsSql,
// schema,
// );

// writeResult({
// cur: schema,
// sqlStatements,
// journal,
// _meta,
// outFolder: out,
// breakpoints,
// type: 'introspect',
// prefixMode: prefix,
// });
// } else {
// render(
// `[${
// chalk.blue(
// 'i',
// )
// }] No SQL generated, you already have migrations in project`,
// );
// }

// render(
// `[${
// chalk.green(
// '✓',
// )
// }] Your schema file is ready ➜ ${chalk.bold.underline.blue(schemaFile)} 🚀`,
// );
// render(
// `[${
// chalk.green(
// '✓',
// )
// }] Your relations file is ready ➜ ${
// chalk.bold.underline.blue(
// relationsFile,
// )
// } 🚀`,
// );
// process.exit(0);
// };

export const introspectSingleStore = async (
casing: Casing,
out: string,
Expand Down
137 changes: 137 additions & 0 deletions drizzle-kit/src/cli/commands/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs';
import {
// prepareMsSqlDbPushSnapshot,
// prepareMsSqlMigrationSnapshot,
prepareMySqlDbPushSnapshot,
prepareMySqlMigrationSnapshot,
preparePgDbPushSnapshot,
Expand All @@ -13,6 +15,7 @@ import {
import chalk from 'chalk';
import { render } from 'hanji';
import path, { join } from 'path';
import { MsSqlSchema, mssqlSchema, squashMssqlScheme } from 'src/serializer/mssqlSchema';
import { SingleStoreSchema, singlestoreSchema, squashSingleStoreScheme } from 'src/serializer/singlestoreSchema';
import { TypeOf } from 'zod';
import type { CommonSchema } from '../../schemaValidator';
Expand All @@ -21,6 +24,7 @@ import { PgSchema, pgSchema, Policy, Role, squashPgScheme, View } from '../../se
import { SQLiteSchema, sqliteSchema, squashSqliteScheme, View as SQLiteView } from '../../serializer/sqliteSchema';
import {
applyLibSQLSnapshotsDiff,
applyMssqlSnapshotsDiff,
applyMysqlSnapshotsDiff,
applyPgSnapshotsDiff,
applySingleStoreSnapshotsDiff,
Expand Down Expand Up @@ -674,6 +678,7 @@ export const prepareSingleStorePush = async (
}
};

// singlestore
export const prepareAndMigrateSingleStore = async (config: GenerateConfig) => {
const outFolder = config.out;
const schemaPath = config.schema;
Expand Down Expand Up @@ -799,6 +804,7 @@ export const prepareAndExportMysql = async (config: ExportConfig) => {
}
};

// sqlite
export const prepareAndMigrateSqlite = async (config: GenerateConfig) => {
const outFolder = config.out;
const schemaPath = config.schema;
Expand Down Expand Up @@ -1054,6 +1060,137 @@ export const prepareLibSQLPush = async (
};
};

// TODO() mssql
// export const prepareAndExportMssql = async (config: ExportConfig) => {
// const schemaPath = config.schema;

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

// const validatedPrev = mssqlSchema.parse(prev);
// const validatedCur = mssqlSchema.parse(cur);

// const squashedPrev = squashMssqlScheme(validatedPrev);
// const squashedCur = squashMssqlScheme(validatedCur);

// const { sqlStatements, statements, _meta } = await applyMssqlSnapshotsDiff(
// squashedPrev,
// squashedCur,
// tablesResolver,
// columnsResolver,
// mySqlViewsResolver,
// validatedPrev,
// validatedCur,
// );

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

// Intersect with prepareAnMigrate
// export const prepareMsSQLPush = async (
// schemaPath: string | string[],
// snapshot: MsSqlSchema,
// casing: CasingType | undefined,
// ) => {
// try {
// const { prev, cur } = await prepareMsSqlDbPushSnapshot(
// snapshot,
// schemaPath,
// casing,
// );

// const validatedPrev = mssqlSchema.parse(prev);
// const validatedCur = mssqlSchema.parse(cur);

// const squashedPrev = squashMssqlScheme(validatedPrev);
// const squashedCur = squashMssqlScheme(validatedCur);

// const { sqlStatements, statements } = await applyMssqlSnapshotsDiff(
// squashedPrev,
// squashedCur,
// tablesResolver,
// columnsResolver,
// mySqlViewsResolver,
// validatedPrev,
// validatedCur,
// 'push',
// );

// return { sqlStatements, statements, validatedCur, validatedPrev };
// } catch (e) {
// console.error(e);
// process.exit(1);
// }
// };

export const prepareAndMigrateMsSQL = async (config: GenerateConfig) => {
const outFolder = config.out;
const schemaPath = config.schema;
const casing = config.casing;

try {
// TODO: remove
// assertV1OutFolder(outFolder);

// const { snapshots, journal } = prepareMigrationFolder(outFolder, 'mssql');
// const { prev, cur, custom } = await prepareMsSqlMigrationSnapshot(
// snapshots,
// schemaPath,
// casing,
// );

// const validatedPrev = mssqlSchema.parse(prev);
// const validatedCur = mssqlSchema.parse(cur);

// if (config.custom) {
// writeResult({
// cur: custom,
// sqlStatements: [],
// journal,
// outFolder,
// name: config.name,
// breakpoints: config.breakpoints,
// type: 'custom',
// prefixMode: config.prefix,
// });
// return;
// }

// const squashedPrev = squashMssqlScheme(validatedPrev);
// const squashedCur = squashMssqlScheme(validatedCur);

// const { sqlStatements, statements, _meta } = await applyMssqlSnapshotsDiff(
// squashedPrev,
// squashedCur,
// tablesResolver,
// columnsResolver,
// mySqlViewsResolver,
// validatedPrev,
// validatedCur,
// );

// writeResult({
// cur,
// sqlStatements,
// journal,
// _meta,
// outFolder,
// name: config.name,
// breakpoints: config.breakpoints,
// prefixMode: config.prefix,
// });
} catch (e) {
console.error(e);
}
};

const freeeeeeze = (obj: any) => {
Object.freeze(obj);
for (let key in obj) {
Expand Down
53 changes: 53 additions & 0 deletions drizzle-kit/src/cli/commands/mssqlIntrospect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { renderWithTask } from 'hanji';
import { Minimatch } from 'minimatch';
import { MsSqlSchema } from 'src/serializer/mssqlSchema';
import { fromDatabase } from 'src/serializer/mssqlSerializer';
import { originUUID } from '../../global';
import type { DB } from '../../utils';
import { ProgressView } from '../views';

export const mssqlPushIntrospect = async (
db: DB,
databaseName: string,
filters: string[],
) => {
const matchers = filters.map((it) => {
return new Minimatch(it);
});

const filter = (tableName: string) => {
if (matchers.length === 0) return true;

let flags: boolean[] = [];

for (let matcher of matchers) {
if (matcher.negate) {
if (!matcher.match(tableName)) {
flags.push(false);
}
}

if (matcher.match(tableName)) {
flags.push(true);
}
}

if (flags.length > 0) {
return flags.every(Boolean);
}
return false;
};

const progress = new ProgressView(
'Pulling schema from database...',
'Pulling schema from database...',
);
const res = await renderWithTask(
progress,
fromDatabase(db, databaseName, filter),
);

const schema = { id: originUUID, prevId: '', ...res } as MsSqlSchema;
const { internal, ...schemaWithoutInternals } = schema;
return { schema: schemaWithoutInternals };
};
Loading