drizzle-kit 0.9.46 → 0.9.49

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 +1010 -2847
  2. package/package.json +4 -3
  3. package/readme.md +83 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.9.46",
3
+ "version": "0.9.49",
4
4
  "author": "Alex Blokh <aleksandrblokh@gmail.com>",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  "@types/js-yaml": "^4.0.3",
29
29
  "@types/pg": "^8.6.1",
30
30
  "@typescript-eslint/eslint-plugin": "4.4.1",
31
- "drizzle-orm": "^0.10.25",
31
+ "drizzle-orm": "^0.11.2",
32
32
  "esbuild-register": "^3.3.2",
33
33
  "eslint": "^7.2.0",
34
34
  "eslint-config-airbnb": "18.2.1",
@@ -46,5 +46,6 @@
46
46
  "test": "uvu -r esbuild-register ./tests/",
47
47
  "imports": "ts-node ./test.ts",
48
48
  "build": "esbuild ./src/cli/index.ts --bundle --platform=node --target=node10.4 --outfile=./dist/index.js --external:esbuild"
49
- }
49
+ },
50
+ "readme": "## Drizzle Kit\nDrizzleKit - 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.\n\n### How it works\n`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.\n\nFor schema file:\n```typescript\nimport { AbstractTable } from \"drizzle-orm\";\n\nexport class UsersTable extends AbstractTable<UsersTable> {\n public id = this.serial(\"id\").primaryKey();\n public fullName = this.varchar(\"full_name\", { size: 256 });\n\n public fullNameIndex = this.index(this.fullName);\n\n public tableName(): string {\n return \"users\";\n }\n}\n\nexport class AuthOtpTable extends AbstractTable<AuthOtpTable> {\n public id = this.serial(\"id\").primaryKey();\n public phone = this.varchar(\"phone\", { size: 256 });\n public userId = this.int(\"user_id\").foreignKey(UsersTable, (t) => t.id);\n\n public tableName(): string {\n return \"auth_otp\";\n }\n}\n```\nIt will generate:\n```SQL\nCREATE TABLE IF NOT EXISTS auth_otp (\n\t\"id\" SERIAL PRIMARY KEY,\n\t\"phone\" character varying(256),\n\t\"user_id\" INT\n);\n\nCREATE TABLE IF NOT EXISTS users (\n\t\"id\" SERIAL PRIMARY KEY,\n\t\"full_name\" character varying(256)\n);\n\nDO $$ BEGIN\n ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY (\"user_id\") REFERENCES users(id);\nEXCEPTION\n WHEN duplicate_object THEN null;\nEND $$;\n\nCREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);\n```\n\n### Installation & configuration\n```bash\nnpm install -g drizzle-kit\n```\nCreate a `drizzle.config.yml` configuration file:\n```yaml\nmigrationRootFolder: drizzle ## all migrations will live here\ndataFolder: './src/data' ## where are all schema .ts files\n```\n \\\nThat's it, you're ready to go 🚀\n```\n> drizzle-kit migrate\n```\n \\\nYou can also run migrations in project scope\n```js\n// package.json\n{\n ...\n scripts: {\n ...\n migrate: \"drizzle-kit migrate\"\n }\n}\n\n> npm run migrate\n```\n \n\n"
50
51
  }
package/readme.md ADDED
@@ -0,0 +1,83 @@
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.
3
+
4
+ ### 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
+
7
+ For schema file:
8
+ ```typescript
9
+ import { AbstractTable } from "drizzle-orm";
10
+
11
+ export class UsersTable extends AbstractTable<UsersTable> {
12
+ public id = this.serial("id").primaryKey();
13
+ public fullName = this.varchar("full_name", { size: 256 });
14
+
15
+ public fullNameIndex = this.index(this.fullName);
16
+
17
+ public tableName(): string {
18
+ return "users";
19
+ }
20
+ }
21
+
22
+ export class AuthOtpTable extends AbstractTable<AuthOtpTable> {
23
+ public id = this.serial("id").primaryKey();
24
+ public phone = this.varchar("phone", { size: 256 });
25
+ public userId = this.int("user_id").foreignKey(UsersTable, (t) => t.id);
26
+
27
+ public tableName(): string {
28
+ return "auth_otp";
29
+ }
30
+ }
31
+ ```
32
+ It will generate:
33
+ ```SQL
34
+ CREATE TABLE IF NOT EXISTS auth_otp (
35
+ "id" SERIAL PRIMARY KEY,
36
+ "phone" character varying(256),
37
+ "user_id" INT
38
+ );
39
+
40
+ CREATE TABLE IF NOT EXISTS users (
41
+ "id" SERIAL PRIMARY KEY,
42
+ "full_name" character varying(256)
43
+ );
44
+
45
+ DO $$ BEGIN
46
+ ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY ("user_id") REFERENCES users(id);
47
+ EXCEPTION
48
+ WHEN duplicate_object THEN null;
49
+ END $$;
50
+
51
+ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
52
+ ```
53
+
54
+ ### 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
62
+ ```
63
+ \
64
+ That's it, you're ready to go 🚀
65
+ ```
66
+ > drizzle-kit migrate
67
+ ```
68
+ \
69
+ You can also run migrations in project scope
70
+ ```js
71
+ // package.json
72
+ {
73
+ ...
74
+ scripts: {
75
+ ...
76
+ migrate: "drizzle-kit migrate"
77
+ }
78
+ }
79
+
80
+ > npm run migrate
81
+ ```
82
+
83
+