drizzle-kit 0.12.2 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +8 -8
  2. package/package.json +1 -1
  3. package/readme.md +61 -44
package/index.js CHANGED
@@ -17969,7 +17969,7 @@ var PgSquasher = {
17969
17969
  const result = index.parse({
17970
17970
  name,
17971
17971
  columns: columnsString.split(","),
17972
- isUnique: Boolean(isUnique)
17972
+ isUnique: isUnique === "true"
17973
17973
  });
17974
17974
  return result;
17975
17975
  },
@@ -18032,7 +18032,7 @@ var generatePgSnapshot = (tables, enums) => {
18032
18032
  if (column3.default instanceof import_sql.SQL) {
18033
18033
  columnToSet.default = column3.default.queryChunks.map((it) => {
18034
18034
  if (typeof it === "string") {
18035
- return `"${it}"`;
18035
+ return `${it}`;
18036
18036
  }
18037
18037
  throw new Error();
18038
18038
  }).join();
@@ -18119,7 +18119,7 @@ var generateMySqlSnapshot = (tables, enums) => {
18119
18119
  if (column3.default instanceof import_sql2.SQL) {
18120
18120
  columnToSet.default = column3.default.queryChunks.map((it) => {
18121
18121
  if (typeof it === "string") {
18122
- return `"${it}"`;
18122
+ return `${it}`;
18123
18123
  }
18124
18124
  throw new Error();
18125
18125
  }).join();
@@ -18460,8 +18460,8 @@ var PgCreateForeignKeyConvertor = class extends Convertor {
18460
18460
  }
18461
18461
  convert(statement) {
18462
18462
  const { name, tableFrom, tableTo, columnsFrom, columnsTo, onDelete, onUpdate } = PgSquasher.unsquashFK(statement.data);
18463
- const onDeleteStatement = onDelete || "";
18464
- const onUpdateStatement = onUpdate || "";
18463
+ const onDeleteStatement = onDelete ? `ON DELETE ${onDelete}` : "";
18464
+ const onUpdateStatement = onUpdate ? `ON UPDATE ${onUpdate}` : "";
18465
18465
  const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
18466
18466
  const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
18467
18467
  const alterStatement = `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
@@ -18479,8 +18479,8 @@ var MySqlCreateForeignKeyConvertor = class extends Convertor {
18479
18479
  }
18480
18480
  convert(statement) {
18481
18481
  const { name, tableFrom, tableTo, columnsFrom, columnsTo, onDelete, onUpdate } = PgSquasher.unsquashFK(statement.data);
18482
- const onDeleteStatement = onDelete || "";
18483
- const onUpdateStatement = onUpdate || "";
18482
+ const onDeleteStatement = onDelete ? `ON DELETE ${onDelete}` : "";
18483
+ const onUpdateStatement = onUpdate ? `ON UPDATE ${onUpdate}` : "";
18484
18484
  const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
18485
18485
  const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
18486
18486
  return `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement};`.replace(/ +/g, " ").trim();
@@ -19008,7 +19008,7 @@ var MySqlSquasher = {
19008
19008
  const result = index2.parse({
19009
19009
  name,
19010
19010
  columns: columnsString.split(","),
19011
- isUnique: Boolean(isUnique),
19011
+ isUnique: isUnique === "true",
19012
19012
  using,
19013
19013
  algorithm,
19014
19014
  lock
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.12.2",
3
+ "version": "0.12.5",
4
4
  "repository": "https://github.com/lambda-direct/drizzle-kit",
5
5
  "author": "Alex Blokh <aleksandrblokh@gmail.com>",
6
6
  "license": "MIT",
package/readme.md CHANGED
@@ -1,33 +1,30 @@
1
1
  ## Drizzle Kit
2
- DrizzleKit - is a CLI migrator tool for DrizzleORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like delitions and renames by prompting user input.
2
+ DrizzleKit - is a CLI migrator tool for DrizzleORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like delitions and renames by prompting user input.\
3
+ https://github.com/drizzle-team/drizzle-kit-mirror - is a mirror repository for issues.
3
4
 
4
5
  ### How it works
5
- `drizzle-kit` will traverse `data folder` from configuration file, find all schema .ts files. Generate schema snapshot and compare it to the previous version(if there's one). Based on the difference it will generate all needed SQL migrations and if there're any `automatically unresolvable` cases like `renames` it will prompt user for input.
6
+ `drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version(if there's one).\
7
+ Based on the difference it will generate all needed SQL migrations and if there're any `automatically unresolvable` cases like `renames` it will prompt user for input.
6
8
 
7
9
  For schema file:
8
10
  ```typescript
9
- import { AbstractTable } from "drizzle-orm";
11
+ // ./src/db/schema.ts
10
12
 
11
- export class UsersTable extends AbstractTable<UsersTable> {
12
- id = this.serial("id").primaryKey();
13
- fullName = this.varchar("full_name", { size: 256 });
13
+ import { integer, pgTable, serial, text, varchar } from "drizzle-orm-pg";
14
14
 
15
- fullNameIndex = this.index(this.fullName);
16
-
17
- public tableName(): string {
18
- return "users";
19
- }
20
- }
21
-
22
- export class AuthOtpTable extends AbstractTable<AuthOtpTable> {
23
- id = this.serial("id").primaryKey();
24
- phone = this.varchar("phone", { size: 256 });
25
- userId = this.int("user_id").foreignKey(UsersTable, (t) => t.id);
15
+ const users = pgTable("users", {
16
+ id: serial("id").primaryKey(),
17
+ fullName: varchar("full_name", { length: 256 }),
18
+ }, (table) => ({
19
+ nameIdx: index("name_idx", table.fullName),
20
+ })
21
+ );
26
22
 
27
- public tableName(): string {
28
- return "auth_otp";
29
- }
30
- }
23
+ export const authOtp = pgTable("auth_otp", {
24
+ id: serial("id").primaryKey(),
25
+ phone: varchar("phone", { length: 256 }),
26
+ userId: integer("user_id").references(() => users.id),
27
+ });
31
28
  ```
32
29
  It will generate:
33
30
  ```SQL
@@ -52,32 +49,52 @@ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
52
49
  ```
53
50
 
54
51
  ### Installation & configuration
55
- ```bash
56
- npm install -g drizzle-kit
57
- ```
58
- Create a `drizzle.config.yml` configuration file:
59
- ```yaml
60
- migrationRootFolder: drizzle ## all migrations will live here
61
- dataFolder: './src/data' ## where are all schema .ts files
52
+ ```shell
53
+ $ npm install -D drizzle-kit
62
54
  ```
63
- \
64
- That's it, you're ready to go 🚀
65
- ```
66
- > drizzle-kit migrate
55
+
56
+ Running with CLI options
57
+ ```shell
58
+ $ npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
67
59
  ```
68
- \
69
- You can also run migrations in project scope
70
- ```js
71
- // package.json
60
+
61
+ Or put your file to `drizzle.config.json` configuration file:
62
+ ```json
72
63
  {
73
- ...
74
- scripts: {
75
- ...
76
- migrate: "drizzle-kit migrate"
77
- }
64
+ "dialect": "pg",
65
+ "out": "./migrations-folder",
66
+ "schema": "./src/db"
78
67
  }
79
-
80
- > npm run migrate
81
68
  ```
82
-
69
+ ---
70
+ ### List of commands
71
+ **`$ drizzle-kit generate`** - generates SQL migrations based on .ts schema\
72
+ `--config` [optional defalut=drizzle.config.json] path to an optional config file\
73
+ `--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
74
+ `--schema` path to a schema file or folder with multiple schema files\
75
+ `--out` [optional default=drizzle/] place where to store migration files\
76
+ ```shell
77
+ $ drizzle-kit generate
78
+ ## runs generate command with drizzle.config.json
79
+
80
+ $ drizzle-kit generate --config custom.config.json
81
+ ## runs generate command with custom.config.json
82
+
83
+ $ drizzle-kit generate --dialect pg --schema src/schema.ts
84
+ ## runs generate command and outputs results to ./drizzle
85
+
86
+ $ drizzle-kit generate --dialect .. --schema .. --out ./migration-folder
87
+ ## runs generate command and outputs results to ./migration-folder
88
+ ```
89
+ **`$ drizzle-kit up`** - updates stale snapshots
90
+ `--config` [optional defalut=drizzle.config.json] path to an optional config file\
91
+ `--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
92
+ `--schema` path to a schema file or folder with multiple schema files\
93
+
94
+ **`$ drizzle-kit check`** - checks for collisions
95
+ `--config` [optional defalut=drizzle.config.json] path to an optional config file\
96
+ `--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
97
+ `--schema` path to a schema file or folder with multiple schema files\
98
+
99
+
83
100