Skip to content

Commit

Permalink
Merge pull request #2822 from drizzle-team/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
AndriiSherman authored Aug 22, 2024
2 parents 6adbd78 + f7ddd08 commit 90c4788
Show file tree
Hide file tree
Showing 16 changed files with 879 additions and 517 deletions.
32 changes: 32 additions & 0 deletions changelogs/drizzle-kit/0.24.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Bug fixes

> Big thanks to @L-Mario564 for his [PR](https://github.com/drizzle-team/drizzle-orm/pull/2804). It conflicted in most cases with a PR that was merged, but we incorporated some of his logic. Merging it would have caused more problems and taken more time to resolve, so we just took a few things from his PR, like removing "::<type>" mappings in introspect and some array type default handlers
### What was fixed

1. The Drizzle Kit CLI was not working properly for the `introspect` command.
2. Added the ability to use column names with special characters for all dialects.
3. Included PostgreSQL sequences in the introspection process.
4. Reworked array type introspection and added all test cases.
5. Fixed all (we hope) default issues in PostgreSQL, where `::<type>` was included in the introspected output.
6. `preserve` casing option was broken

### Tickets that were closed

- [[BUG]: invalid schema generation with drizzle-kit introspect:pg](https://github.com/drizzle-team/drizzle-orm/issues/1210)
- [[BUG][mysql introspection]: TS error when introspect column including colon](https://github.com/drizzle-team/drizzle-orm/issues/1928)
- [[BUG]: Unhandled defaults when introspecting postgres db](https://github.com/drizzle-team/drizzle-orm/issues/1625)
- [[BUG]: PostgreSQL Enum Naming and Schema Typing Issue](https://github.com/drizzle-team/drizzle-orm/issues/2315)
- [[BUG]: drizzle-kit instrospect command generates syntax error on varchar column types](https://github.com/drizzle-team/drizzle-orm/issues/2714)
- [[BUG]: Introspecting varchar[] type produces syntactically invalid schema.ts](https://github.com/drizzle-team/drizzle-orm/issues/1633)
- [[BUG]: introspect:pg column not using generated enum name](https://github.com/drizzle-team/drizzle-orm/issues/1648)
- [[BUG]: drizzle-kit introspect casing "preserve" config not working](https://github.com/drizzle-team/drizzle-orm/issues/2773)
- [[BUG]: drizzle-kit introspect fails on required param that is defined](https://github.com/drizzle-team/drizzle-orm/issues/2719)
- [[BUG]: Error when running npx drizzle-kit introspect: "Expected object, received string"](https://github.com/drizzle-team/drizzle-orm/issues/2657)
- [[BUG]: Missing index names when running introspect command [MYSQL]](https://github.com/drizzle-team/drizzle-orm/issues/2525)
- [[BUG]: drizzle-kit introspect TypeError: Cannot read properties of undefined (reading 'toLowerCase')](https://github.com/drizzle-team/drizzle-orm/issues/2338)
- [[BUG]: Wrong column name when using PgEnum.array()](https://github.com/drizzle-team/drizzle-orm/issues/2100)
- [[BUG]: Incorrect Schema Generated when introspecting extisting pg database](https://github.com/drizzle-team/drizzle-orm/issues/1985)
- [[⚠️🐞BUG]: index() missing argument after introspection, causes tsc error that fails the build](https://github.com/drizzle-team/drizzle-orm/issues/1870)
- [[BUG]: drizzle-kit introspect small errors](https://github.com/drizzle-team/drizzle-orm/issues/1738)
- [[BUG]: Missing bigint import in drizzle-kit introspect](https://github.com/drizzle-team/drizzle-orm/issues/1020)
6 changes: 3 additions & 3 deletions drizzle-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-kit",
"version": "0.24.0",
"version": "0.24.1",
"homepage": "https://orm.drizzle.team",
"keywords": [
"drizzle",
Expand Down Expand Up @@ -42,7 +42,7 @@
"publish": "npm publish package.tgz"
},
"dependencies": {
"@drizzle-team/brocli": "^0.8.2",
"@drizzle-team/brocli": "^0.10.1",
"@esbuild-kit/esm-loader": "^2.5.5",
"esbuild": "^0.19.7",
"esbuild-register": "^3.5.0"
Expand Down Expand Up @@ -92,7 +92,7 @@
"hono": "^4.1.5",
"json-diff": "1.0.6",
"minimatch": "^7.4.3",
"mysql2": "2.3.3",
"mysql2": "3.3.3",
"node-fetch": "^3.3.2",
"pg": "^8.11.5",
"pluralize": "^8.0.0",
Expand Down
12 changes: 6 additions & 6 deletions drizzle-kit/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ export const preparePullConfig = async (
dialect: 'postgresql',
out: config.out,
breakpoints: config.breakpoints,
casing: config.introspectCasing,
casing: config.casing,
credentials: parsed.data,
tablesFilter,
schemasFilter,
prefix: config.database?.prefix || 'index',
prefix: config.migrations?.prefix || 'index',
};
}

Expand All @@ -426,11 +426,11 @@ export const preparePullConfig = async (
dialect: 'mysql',
out: config.out,
breakpoints: config.breakpoints,
casing: config.introspectCasing,
casing: config.casing,
credentials: parsed.data,
tablesFilter,
schemasFilter,
prefix: config.database?.prefix || 'index',
prefix: config.migrations?.prefix || 'index',
};
}

Expand All @@ -444,11 +444,11 @@ export const preparePullConfig = async (
dialect: 'sqlite',
out: config.out,
breakpoints: config.breakpoints,
casing: config.introspectCasing,
casing: config.casing,
credentials: parsed.data,
tablesFilter,
schemasFilter,
prefix: config.database?.prefix || 'index',
prefix: config.migrations?.prefix || 'index',
};
}

Expand Down
1 change: 1 addition & 0 deletions drizzle-kit/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ const legacy = [
];

run([generate, migrate, pull, push, studio, up, check, drop, ...legacy], {
name: 'drizzle-kit',
version: version,
});
4 changes: 2 additions & 2 deletions drizzle-kit/src/cli/validations/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export const pullParams = object({
.optional()
.default(['public']),
extensionsFilters: literal('postgis').array().optional(),
introspectCasing: casing,
casing,
breakpoints: boolean().optional().default(true),
database: object({
migrations: object({
prefix: prefix.optional().default('index'),
}).optional(),
}).passthrough();
Expand Down
15 changes: 11 additions & 4 deletions drizzle-kit/src/introspect-mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,22 @@ const importsPatch = {

const relations = new Set<string>();

const escapeColumnKey = (value: string) => {
if (/^(?![a-zA-Z_$][a-zA-Z0-9_$]*$).+$/.test(value)) {
return `"${value}"`;
}
return value;
};

const prepareCasing = (casing?: Casing) => (value: string) => {
if (typeof casing === 'undefined') {
return value;
if (casing === 'preserve') {
return escapeColumnKey(value);
}
if (casing === 'camel') {
return value.camelCase();
return escapeColumnKey(value.camelCase());
}

return value;
return escapeColumnKey(value);
};

export const schemaToTypeScript = (
Expand Down
Loading

0 comments on commit 90c4788

Please sign in to comment.