{"id":22725405,"url":"https://github.com/ovotech/pg-sql-migrate","last_synced_at":"2025-04-13T20:28:31.885Z","repository":{"id":41600978,"uuid":"200368819","full_name":"ovotech/pg-sql-migrate","owner":"ovotech","description":"A very small library for running sql migrations with postgres.","archived":false,"fork":false,"pushed_at":"2023-07-18T21:14:50.000Z","size":408,"stargazers_count":2,"open_issues_count":9,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-29T00:23:35.824Z","etag":null,"topics":["company-ovo"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ovotech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-03T11:41:40.000Z","updated_at":"2024-06-21T13:06:11.644Z","dependencies_parsed_at":"2024-06-21T13:06:05.826Z","dependency_job_id":"b11bfc6a-6797-4806-a671-bbcdf0e80cda","html_url":"https://github.com/ovotech/pg-sql-migrate","commit_stats":{"total_commits":43,"total_committers":4,"mean_commits":10.75,"dds":"0.11627906976744184","last_synced_commit":"ce82b1ed67ebac94414b95ab1d2a49012018da44"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fpg-sql-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fpg-sql-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fpg-sql-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fpg-sql-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ovotech","download_url":"https://codeload.github.com/ovotech/pg-sql-migrate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229089204,"owners_count":18018390,"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":["company-ovo"],"created_at":"2024-12-10T16:10:06.560Z","updated_at":"2024-12-10T16:10:07.366Z","avatar_url":"https://github.com/ovotech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postgres migration tool with plain sql\n\nA very small library for running sql migrations with postgres. It differs from the numerous other libs in this domain by being very minimal, using only raw timestamped sql files. No \"down\" migrations are provided by design, as that is usually a bad idea in production anyway.\n\n## Using with CLI\n\n```bash\nyarn add @ovotech/pg-sql-migrate\n```\n\nadd a configuration file, which by default is `./pg-sql-migrate.config.json` to configure the connection:\n\n```json\n{\n  \"client\": \"postgresql://postgres:dev-pass@localhost:5432/postgres\",\n  \"directory\": \"migrations\",\n  \"table\": \"migrations\"\n}\n```\n\nThe default values for \"directory\" and \"table\" configuration is `migrations` but you can override that if you need to.\n\nInstead of a string you can use an object. This is passed directly to pg https://node-postgres.com/features/connecting\n\n```json\n{\n  \"client\": {\n    \"user\": \"postgres\",\n    \"password\": \"dev-pass\",\n    \"host\": \"localhost\",\n    \"database\": \"postgres\",\n    \"port\": 5432\n  }\n}\n```\n\nTo create new migrations in the designated directory you can run:\n\n```bash\nyarn migrate create my_migration\n```\n\nThis will create a file `migrations/\u003ctimestamp\u003e_my_migration.pgsql` that you can place raw sql into. After that, you can run the migration(s) by calling\n\n```bash\nyarn migrate execute\n```\n\nYou can also specify the configuration as cli options\n\n```bash\nyarn migrate execute --config-directory ~/my/dir/migrations --config-table my-table --config-client postgresql://localhost:5432/my-database\n```\n\nIn you code you can run it as a library\n\n```typescript\nimport { migrate } from '@ovotech/pg-sql-migrate';\n\nawait migrate();\n```\n\n## Environment variables\n\nIn your config file you can use environment variables.\n\nFor example, if you have the env var `PG_USER_PASS` setup, you can access it with:\n\n```json\n{\n  \"client\": \"postgresql://postgres:${PG_USER_PASS}@localhost:5432/postgres\",\n  \"directory\": \"migrations\"\n  \"table\" \"migrations\"\n}\n```\n\n## Using the library\n\nYou can choose a different location for the config file, or to just input its contents directly:\n\n```typescript\nimport { migrate } from '@ovotech/pg-sql-migrate';\nimport { createLogger } from 'winston';\n\nawait migrate();\n\nawait migrate({ config: 'custom-config.json' });\n\nawait migrate({\n  config: {\n    client: 'postgresql://postgres:dev-pass@localhost:5432/postgres',\n    // Custom table location\n    table: 'my_table',\n    // Custom directory for migration files\n    directory: 'migrations_dir',\n  },\n});\n\n// Custom logger\nconst logger = createLogger();\nawait migrate({ logger });\n\n// Dry run\nawait migrate({ dryRun: true });\n```\n\n## Distabling transactions for some migrations\n\nBy default migrations are wrapped in transactions, but there are some PG operations that cannot be performed inside a transaction. You can disable this for a specific transaction by adding a prefix\n\n```sql\n-- pg-sql-migrate: DISABLE TRANSACTION\nALTER TYPE my_type ADD VALUE 'VAL2' AFTER 'VAL1';\n```\n\n## Running the tests\n\nYou can run the tests with:\n\n```bash\nyarn test\n```\n\n### Coding style (linting, etc) tests\n\nStyle is maintained with prettier and eslint\n\n```\nyarn lint\n```\n\n## Deployment\n\nDeployment is preferment by circleci automatically on merge / push to master, but you'll need to bump the package version numbers yourself.\n\n## Contributing\n\nHave a bug? File an issue with a simple example that reproduces this so we can take a look \u0026 confirm.\n\nWant to make a change? Submit a PR, explain why it's useful, and make sure you've updated the docs (this file) and the tests (see [test folder](test)).\n\n## License\n\nThis project is licensed under Apache 2 - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovotech%2Fpg-sql-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovotech%2Fpg-sql-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovotech%2Fpg-sql-migrate/lists"}