Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new `pgroll pull` command that pulls the complete migration history for a schema from the `migrations` table in the target database and dumps the migrations to disk. ## Example Given the migration history in `pgroll.migrations` after applying all `example/` migrations in this repo: ``` +--------+-----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> | schema | name | migration > |--------+-----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> | public | 01_create_tables | {"name": "01_create_tables", "operations": [{"create_table": {"name": "customers", "columns": [{"pk": true, "name": "id", "type": "integer"}, {"name": "name", "type": "varchar(255)", "unique": true}, {"name": "credit_card", "type": "text", "nullab> | public | 02_create_another_table | {"name": "02_create_another_table", "operations": [{"create_table": {"name": "products", "columns": [{"pk": true, "name": "id", "type": "serial"}, {"name": "name", "type": "varchar(255)", "unique": true}, {"name": "price", "type": "decimal(10,2)"}> | public | 03_add_column_to_products | {"name": "03_add_column_to_products", "operations": [{"add_column": {"up": "UPPER(name)", "table": "products", "column": {"name": "description", "type": "varchar(255)", "nullable": true}}}, {"add_column": {"table": "products", "column": {"name": "> | public | 04_rename_table | {"name": "04_rename_table", "operations": [{"rename_table": {"to": "clients", "from": "customers"}}]} > | public | 05_sql | {"name": "05_sql", "operations": [{"sql": {"up": "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)", "down": "DROP TABLE users"}}]} > | public | 06_add_column_to_sql_table | {"name": "06_add_column_to_sql_table", "operations": [{"add_column": {"up": "UPPER(name)", "table": "users", "column": {"name": "description", "type": "varchar(255)", "nullable": true}}}]} > ... ``` Run: ```bash $ pgroll pull migrations/ ``` This will pull all migrations from the `pgroll.migrations` table into the `migrations/` directory: ``` $ ls migrations/ 01_create_tables.json 02_create_another_table.json 03_add_column_to_products.json 04_rename_table.json 05_sql.json 06_add_column_to_sql_table.json ... ``` The optional `--with-prefixes` flag prefixes each migration name with its position in the schema history: ```bash $ pgroll pull --with-prefixes migrations/ ``` This produces the following files: ``` $ ls migrations/ 0001_01_create_tables.json 0002_02_create_another_table.json 0003_03_add_column_to_products.json 0004_04_rename_table.json 0005_05_sql.json 0006_06_add_column_to_sql_table.json ... ``` The `--with-prefixes` flag ensures that files are sorted lexicographically by their time of application.
- Loading branch information