sqerge 1.0.0 → 1.0.1
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.
- package/README.md +69 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,64 +4,72 @@ A forward only PostgreSQL migration tool. Uses [Postgres.js](https://github.com/
|
|
|
4
4
|
|
|
5
5
|
## Get Started
|
|
6
6
|
|
|
7
|
-
1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
7
|
+
1. Install NPM package
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i sqerge -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. Install Postgres.js (may install as peerDependency automatically on NPM v7+)
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm i postgres
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
3. Choose a migration directory
|
|
20
|
+
```sh
|
|
21
|
+
mkdir foo
|
|
22
|
+
```
|
|
23
|
+
4. Create some migration files
|
|
24
|
+
|
|
25
|
+
The filename **prefix** represents the execution order, a unique integer followed by a hyphen. After the hyphen, it's all yours. Files not matching the prefix are ignored.
|
|
26
|
+
|
|
27
|
+
```sql
|
|
28
|
+
-- file: ./foo/1-bar.sql
|
|
29
|
+
|
|
30
|
+
CREATE TABLE person (
|
|
31
|
+
"id" SERIAL PRIMARY KEY,
|
|
32
|
+
"name" text NOT NULL
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```sql
|
|
37
|
+
-- file: ./foo/2-biz.sql
|
|
38
|
+
|
|
39
|
+
ALTER TABLE person
|
|
40
|
+
ADD COLUMN "age" smallint;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
In addition to **.sql**, migration files can also end in **.js** or **.mjs** for ES Modules. JavaScript files must **default export a function**. The 1st argument is a [Postgres.js](https://github.com/porsager/postgres) instance.
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// file: ./foo/3-baz.js
|
|
47
|
+
|
|
48
|
+
module.exports = async (sql) => {
|
|
49
|
+
await sql`
|
|
50
|
+
INSERT INTO person
|
|
51
|
+
("name", "age")
|
|
52
|
+
VALUES
|
|
53
|
+
('Luke Skywalker', '21');
|
|
54
|
+
`;
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
5. Execute migration
|
|
59
|
+
|
|
60
|
+
Command:
|
|
61
|
+
|
|
62
|
+
**Note:** Use [environment variables](https://www.postgresql.org/docs/current/libpq-envars.html) for your database connection. Supported environment variables are at the discretion of [Postgres.js](https://github.com/porsager/postgres).
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
PGHOST=localhost PGPORT=5438 PGUSER=jonathan PGPASSWORD=iliketurtles PGDATABASE=dev npx sqerge ./foo
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Output:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
[sqerge] 3 file(s) found in '/Users/jonathan/Desktop/foo'
|
|
72
|
+
[sqerge] file 1 (1-bar.sql): executed
|
|
73
|
+
[sqerge] file 2 (2-biz.sql): executed
|
|
74
|
+
[sqerge] file 3 (3-baz.js): executed
|
|
75
|
+
```
|