Skip to content

Commit c735de2

Browse files
committed
docs.
1 parent 99d3027 commit c735de2

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

README.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ metagration is a script defined entirely within the database, there is
4141
no external migration tool or language.
4242

4343
Metagration `script`s are what move the database from one revision to
44-
the next. Forward metagration runs the "up" procedure, and backward
45-
metagration runs the "down" procedure to undo the "up" operation.
46-
Script procedures can be written in *any* supported stored procedure
44+
the next. Each script has a forward "up" procedure, and optionally a
45+
backward "down" procedure to undo the "up" operation. Script
46+
procedures can be written in *any* supported stored procedure
4747
language. Metagration strictly enforces the revision order of the
4848
scripts applied.
4949

@@ -59,7 +59,7 @@ counterparts:
5959
--------
6060
1
6161

62-
This creates a new revision `1`. The function
62+
This creates a new script with revision `1`. The function
6363
`metagration.new_script(up[, down])` expands the up and down code into
6464
dynamically created plpgsql functions. Once the script is created, it
6565
can then be run with `metagration.run()`
@@ -154,12 +154,12 @@ variable `i` in the `FOR` loops are declared in the `up_declare` and
154154
SELECT new_script(
155155
$up$
156156
FOR i IN (SELECT * FROM generate_series(1, (args->>'target')::bigint, 1)) LOOP
157-
EXECUTE format('CREATE TABLE %I (id serial)', 'forks_' || i);
157+
EXECUTE format('CREATE TABLE %I (id serial)', 'foo_' || i);
158158
END LOOP
159159
$up$,
160160
$down$
161161
FOR i IN (SELECT * FROM generate_series(1, (args->>'target')::bigint, 1)) LOOP
162-
EXECUTE format('DROP TABLE %I', 'forks_' || i);
162+
EXECUTE format('DROP TABLE %I', 'foo_' || i);
163163
END LOOP
164164
$down$,
165165
up_declare:='i bigint',
@@ -171,11 +171,11 @@ To run, pass an integer value for the `target` jsonb key in `args`:
171171
# CALL metagration.run(args:=jsonb_build_object('target', 3));
172172
# \dt+
173173
List of relations
174-
Schema | Name | Type | Owner | Size | Description
175-
--------+---------+-------+----------+---------+-------------
176-
public | forks_1 | table | postgres | 0 bytes |
177-
public | forks_2 | table | postgres | 0 bytes |
178-
public | forks_3 | table | postgres | 0 bytes |
174+
Schema | Name | Type | Owner | Size | Description
175+
--------+-------+-------+----------+---------+-------------
176+
public | foo_1 | table | postgres | 0 bytes |
177+
public | foo_2 | table | postgres | 0 bytes |
178+
public | foo_3 | table | postgres | 0 bytes |
179179
180180
If your up script depends on `args`, it's likely your down scripts do
181181
too. Pass them as well to revert or, get the args used in the up
@@ -200,26 +200,26 @@ migration from the `migration.log` table where they are saved.
200200

201201
The obvious question is, if metagrations are stored procedures that
202202
makes DDL changes, who CREATEs the metagrations? They can be created
203-
programatically as shown above with `new_script`, or they can be
204-
import and exported using any SQL client or tool.
203+
programatically as shown above with `new_script` or by inserting
204+
directly into the `metagraiton.script` table. They can be imported and
205+
exported using any PostgreSQL client or admin tool. Because
206+
metagrations are in-database, they are dumped and restored when the
207+
database is backed up.
205208

206209
You can still check your metagrations into source control and stream
207210
them into a new database when you initialize it, then call
208211
`metagrate.run()`.
209212

210-
Because metagrations are in-database, they are dumped and restored
211-
when the database is backed up.
212-
213-
Since this process is *decoupled* from the actual migration, it can be
214-
done using any of the many database management tools for
215-
PostgreSQL. Because metagration scripts are stored procedures, they
216-
are stateless database objects that can be exported, imported, dropped
217-
and re-created as necessary.
213+
Since this process of creating metagrations is *decoupled* from the
214+
actual act of migration, it can be done using any of the many database
215+
management tools for PostgreSQL. Because metagration scripts are
216+
stored procedures, they are stateless database objects that can be
217+
exported, imported, dropped and re-created as necessary.
218218

219219
A helpful tool for doing this `metagration.export()`. The `export()`
220220
function will generate SQL script file that `CREATE OR REPLACE`s the
221-
migration scripts. Simply capture the output of this function, for
222-
example with:
221+
migration scripts and optionally clear and run them. Simply capture
222+
the output of this function, for example with:
223223

224224
psql -A -t -U postgres -c 'select metagration.export()' > export_file.sql
225225

0 commit comments

Comments
 (0)