{"id":18742848,"url":"https://github.com/roryq/wrench","last_synced_at":"2025-04-12T21:23:14.791Z","repository":{"id":40492651,"uuid":"271726208","full_name":"RoryQ/wrench","owner":"RoryQ","description":"wrench - Schema management tool for Cloud Spanner (fork of cloudspannerecosystem/wrench with improvements)","archived":false,"fork":false,"pushed_at":"2025-03-20T16:55:34.000Z","size":865,"stargazers_count":13,"open_issues_count":9,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T15:41:57.874Z","etag":null,"topics":["database-migrations","google-cloud-spanner","hacktoberfest","hacktoberfest2022","spanner"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"cloudspannerecosystem/wrench","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RoryQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-12T06:32:20.000Z","updated_at":"2025-03-12T05:02:58.000Z","dependencies_parsed_at":"2023-01-14T11:30:44.539Z","dependency_job_id":"136ace75-fc8e-49ba-a220-ccfea960b838","html_url":"https://github.com/RoryQ/wrench","commit_stats":null,"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoryQ%2Fwrench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoryQ%2Fwrench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoryQ%2Fwrench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoryQ%2Fwrench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoryQ","download_url":"https://codeload.github.com/RoryQ/wrench/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632880,"owners_count":21136770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database-migrations","google-cloud-spanner","hacktoberfest","hacktoberfest2022","spanner"],"created_at":"2024-11-07T16:09:24.988Z","updated_at":"2025-04-12T21:23:14.744Z","avatar_url":"https://github.com/RoryQ.png","language":"Go","readme":"# wrench\n\nThis is a fork of https://github.com/cloudspannerecosystem/wrench with the following improvements\n\n- Records timestamped history of applied migrations, not just the current version number.\n- Supports out of order migrations. Similar to [FlywayDB](https://flywaydb.org/documentation/commandline/migrate#outOfOrder), addresses [golang-migrate/migrate/#278](https://github.com/golang-migrate/migrate/issues/278)\n- Migration locking. Prevents multiple wrench processes from applying the same migration.\n- Automated release builds. Each release has prebuilt binary for multiple os/arch that can be downloaded to your CI environment without requiring golang to build from source.\n- Supports INSERT statements in migration DML scripts. (Not just partitioned DML)\n- Custom intervals for migration sequences. Generated migration files can be numbered by 10s, 100s etc. E.g. `[00010.sql, 00020.sql, 00030.sql]` This is allows hotfixes to be inserted inbetween applied migrations.\n- Export schema to discrete files. Instead of a `schema.sql` containing all the objects. If this is checked into source control this makes diff-ing more consistent as it follows a hierarchy vs moving around in a single file. e.g. `[table/table1.sql, table/table2.sql, index/index1.sql]`\n- Export static data tables by specifying in a `static_data_tables.txt` or `wrench.json` file.\n- Automatically upgrades tracking tables used by [cloudspannerecosystem/wrench](https://github.com/cloudspannerecosystem/wrench) or [golang-migrate/migrate](https://github.com/golang-migrate/migrate) to this version.\n- Skip Versions. Flag `--skip-versions` can be set to skip migrations. Useful for working around unsupported features in the emulator during local development.\n- Repair dirty migrations. If a migration fails the version is marked as dirty. Any partial changes should be reverted manually and the history cleaned\nusing `migrate repair`.\n\n## Onboarding existing databases to wrench\n\nThis fork of wrench uses two additional tables for tracking migrations, `SchemaMigrationsHistory` for all scripts\napplied and `SchemaMigrationsLock` to limit wrench migrations to a single invocation.\nIf coming from a database managed by `golang-migrate` or the `cloudspannerecosystem/wrench` then you will already have a\n`SchemaMigrations` table and no work is needed. You can proceed to use this version of wrench and during the next migration\nit will detect that the `SchemaMigrationsHistory` table is missing, then create and backfill the \"history\" data.\nSubsequent `migrate up` invocations will use the history table instead of the `SchemaMigrations` table to detect unapplied\nmigrations.\n\nIf you have an existing database that is not controlled by any migration tools then you should export the current schema\n(you can use `wrench load`) and use this as the baseline version by saving as `000001.sql` and manually creating a\n`SchemaMigrations` table with a `1` entry. This will initiate the backfill process, skipping the migration for existing\ndatabases but recreating for new databases.\n\n### If you wish to go back to `golang-migrate` or `cloudspannerecosystem/wrench`\nYou can simply drop the `SchemaMigrationsHistory` and `SchemaMigrationsLock` table as the `SchemaMigrations` will be in sync.\n___\n\n## Installation\n\nWith go 1.22 or higher:\n\n```shell\ngo install github.com/roryq/wrench@latest\n```\n\n## Usage\n\n### Prerequisite\n\n```sh\nexport SPANNER_PROJECT_ID=your-project-id\nexport SPANNER_INSTANCE_ID=your-instance-id\nexport SPANNER_DATABASE_ID=your-database-id\n```\n\nYou can also specify project id, instance id and database id by passing them as command arguments.\n\n\u003c!--usage-shell--\u003e\n```\nUsage:\n  wrench [command]\n\nAvailable Commands:\n  create        Create database with tables described in schema file\n  drop          Drop database\n  reset         Equivalent to drop and then create\n  load          Load schema from server to file\n  load-discrete Load schema from server to discrete files per object\n  schema        Runs the migrations against a dockerised spanner emulator, then loads the schema and static data to disk. (Requires docker)\n  apply         Apply DDL file to database\n  migrate       Migrate database\n  truncate      Truncate all tables without deleting a database\n  help          Help about any command\n  completion    Generate the autocompletion script for the specified shell\n\nMigrate database\n\nUsage:\n  wrench migrate [command]\n\nAvailable Commands:\n  create      Create a set of sequential up migrations in directory\n  up          Apply all or N up migrations\n  version     Print current migration version\n  history     Print migration version history\n  setup-lock  Initialise or reset the migration lock\n  repair      If a migration has failed, clean up any schema changes manually then repair the history with this command\n\nFlags:\n      --credentials-file string              Specify Credentials File\n      --database string                      Cloud Spanner database name (optional. if not set, will use $SPANNER_DATABASE_ID value)\n      --detect-partitioned-dml               Automatically detect when a migration contains only Partitioned DML statements, and apply the statements in partition-level transactions via the PartitionedDML API. (optional. if not set, will use $WRENCH_DETECT_PARTITIONED_DML or default to false)\n      --directory string                     Directory that schema file placed (required)\n  -h, --help                                 help for wrench\n      --instance string                      Cloud Spanner instance name (optional. if not set, will use $SPANNER_INSTANCE_ID value)\n      --lock-identifier string               Random identifier used to lock migration operations to a single wrench process. (optional. if not set then it will be generated) (default \"58a4394a-19f9-4dbf-880d-20b6cf169d46\")\n      --partitioned-dml-concurrency uint16   Set the concurrency for Partitioned-DML statements. (optional. if not set, will use $WRENCH_PARTITIONED_DML_CONCURRENCY or default to 1) (default 1)\n      --project string                       GCP project id (optional. if not set, will use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT value)\n      --schema-file string                   Name of schema file (optional. if not set, will use default 'schema.sql' file name)\n      --sequence-interval uint16             Used to generate the next migration id. Rounds up to the next interval. (optional. if not set, will use $WRENCH_SEQUENCE_INTERVAL or default to 1) (default 1)\n      --static-data-tables-file string       File containing list of static data tables to track (optional)\n      --stmt-timeout duration                Set a non-default timeout for statement execution\n      --verbose                              Used to indicate whether to output Migration information during a migration\n  -v, --version                              version for wrench\n\nUse \"wrench [command] --help\" for more information about a command.\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froryq%2Fwrench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froryq%2Fwrench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froryq%2Fwrench/lists"}