Skip to content

Commit

Permalink
Add MySQL tests
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Mario564 committed Oct 2, 2024
1 parent 17f5d8b commit 61faf94
Show file tree
Hide file tree
Showing 5 changed files with 516 additions and 14 deletions.
4 changes: 2 additions & 2 deletions drizzle-kit/src/validate-schema/foreign-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class ValidateForeignKey {
mismatchingDataTypes(foreignKey: Table['foreignKeys'][number]) {
const { columns, foreignColumns } = foreignKey.reference;

const types = `(${columns.map((c) => c.getSQLType()).join(', ')})`;
const foreignTypes = `(${foreignColumns.map((c) => c.getSQLType()).join(', ')})`;
const types = `(${columns.map((c) => c.sqlType).join(', ')})`;
const foreignTypes = `(${foreignColumns.map((c) => c.sqlType).join(', ')})`;

if (types !== foreignTypes) {
this.errors.push({
Expand Down
4 changes: 2 additions & 2 deletions drizzle-kit/src/validate-schema/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export type Table = {
foreignKeys: { name: string; reference: {
columns: {
name: string;
getSQLType: () => string;
sqlType: string;
table: {
name: string;
schema?: string;
};
}[];
foreignColumns: {
name: string;
getSQLType: () => string;
sqlType: string;
table: {
name: string;
schema?: string;
Expand Down
16 changes: 11 additions & 5 deletions drizzle-kit/src/validate-schema/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function validatePgSchema(
const tableConfig = getPgTableConfig(column.table);
return {
name: getColumnCasing(column, casing),
getSQLType: column.getSQLType,
sqlType: column.getSQLType(),
table: {
name: tableConfig.name,
schema: tableConfig.schema
Expand All @@ -134,7 +134,7 @@ export function validatePgSchema(
const tableConfig = getPgTableConfig(column.table);
return {
name: getColumnCasing(column, casing),
getSQLType: column.getSQLType,
sqlType: column.getSQLType(),
table: {
name: tableConfig.name,
schema: tableConfig.schema
Expand Down Expand Up @@ -328,7 +328,7 @@ export function validateMySqlSchema(
const tableConfig = getMySqlTableConfig(column.table);
return {
name: getColumnCasing(column, casing),
getSQLType: column.getSQLType,
sqlType: column.getSQLType(),
table: {
name: tableConfig.name,
schema: tableConfig.schema
Expand All @@ -341,7 +341,7 @@ export function validateMySqlSchema(
const tableConfig = getMySqlTableConfig(column.table);
return {
name: getColumnCasing(column, casing),
getSQLType: column.getSQLType,
sqlType: column.getSQLType(),
table: {
name: tableConfig.name,
schema: tableConfig.schema
Expand Down Expand Up @@ -406,7 +406,8 @@ export function validateMySqlSchema(
};
})();

const v = new ValidateDatabase().validateSchema(undefined);
const vDb = new ValidateDatabase();
const v = vDb.validateSchema(undefined);

v
.constraintNameCollisions(
Expand Down Expand Up @@ -441,6 +442,11 @@ export function validateMySqlSchema(
.validatePrimaryKey(primaryKey.name)
.columnsMixingTables(primaryKey);
}

return {
messages: vDb.errors,
codes: vDb.errorCodes
};
}

export function validateSQLiteSchema(
Expand Down
Loading

0 comments on commit 61faf94

Please sign in to comment.