{"id":27302325,"url":"https://github.com/alfredormz/pg-schema-migration","last_synced_at":"2026-04-26T22:31:38.810Z","repository":{"id":56887940,"uuid":"133162504","full_name":"alfredormz/pg-schema-migration","owner":"alfredormz","description":"Simple schema migrations for PostgreSQL, which runs pure SQL.","archived":false,"fork":false,"pushed_at":"2018-05-12T16:26:18.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-28T06:40:42.024Z","etag":null,"topics":["lesscode","migrations","postgresql","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alfredormz.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":null,"security":null,"support":null}},"created_at":"2018-05-12T16:16:33.000Z","updated_at":"2023-03-05T03:23:53.000Z","dependencies_parsed_at":"2022-08-21T00:50:46.925Z","dependency_job_id":null,"html_url":"https://github.com/alfredormz/pg-schema-migration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alfredormz/pg-schema-migration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredormz%2Fpg-schema-migration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredormz%2Fpg-schema-migration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredormz%2Fpg-schema-migration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredormz%2Fpg-schema-migration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alfredormz","download_url":"https://codeload.github.com/alfredormz/pg-schema-migration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredormz%2Fpg-schema-migration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32315711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T21:09:39.134Z","status":"ssl_error","status_checked_at":"2026-04-26T21:09:21.240Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["lesscode","migrations","postgresql","ruby"],"created_at":"2025-04-12T02:17:40.875Z","updated_at":"2026-04-26T22:31:38.795Z","avatar_url":"https://github.com/alfredormz.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PG Schema Migration\r\n\r\nSimple schema migrations for PostgreSQL, which runs pure SQL. Inspired by [Sequel](https://github.com/jeremyevans/sequel) and [Cassandra Schema](https://github.com/tarolandia/cassandra-schema).\r\n\r\n## Installation\r\n\r\n```\r\ngem install pg-schema-migration\r\n```\r\n\r\n## Usage\r\n\r\nPG::Schema uses a DSL via the `PG::Schema.migration` method, a migration must have an `up` block with the changes you want to apply to the schema, and a `down` block reversing the change made by `up`.\r\n\r\n### A basic Migration\r\n\r\nUse `execute` inside `up` and `down` blocks to run the queries that will modify the schema. Here is a fairly basic `PG::Schema` migration. \r\n\r\n```ruby\r\nPG:Schema.migration do\r\n  up do\r\n    execute \u003c\u003c~SQL\r\n      CREATE TABLE products (\r\n        name VARCHAR(30),\r\n        price NUMERIC\r\n      )\r\n    SQL\r\n    \r\n    execute \"CREATE TRIGGER...\"\r\n  end\r\n  \r\n  down do\r\n    execute \"DROP TABLE products\"\r\n    execute \"DROP TRIGGER...\"\r\n  end\r\nend\r\n```\r\nIf there is an error while running a migration, it will rollback the previous schema changes made by the migration.\r\n\r\n### Running migrations\r\n\r\n```ruby\r\nrequire 'pg/schema-migration'\r\nrequire 'pg'\r\n\r\n@db = PG.connect(ENV.fetch(\"DATABASE_URL\"))\r\n\r\nPG::Schema.migration {...}\r\nPG::Schema.migration {...}\r\n\r\nmigrator = PG::Schema::Migrator.new(\r\n  db:        @db,                   # a PG connection\r\n  directory: 'path/to/migrations',  # default: nil\r\n  log:       Logger.new('/dev/nul') # default: Logger.new(STDOUT)\r\n)\r\n```\r\nMigrate to the latest version\r\n\r\n```ruby\r\nmigrator.run!\r\n```\r\nMigrate to an specific version\r\n\r\n```ruby\r\nmigrator.run!(version: 1)\r\n```\r\n### Migration files\r\n\r\n`PG::Schemas::Migrator` expects that each migration file will be in a specific directory. For example:\r\n\r\n```ruby\r\nPG::Schema::Migrator.new(db: @conn, directory: 'db/migrations').run!\r\n```\r\n\r\n`PG::Schema::Migrator` will look in the `db/migrations` folder relative to the current directory, and run unapplied migrations on the database.\r\n\r\nThe migration files must be specified as follows:\r\n\r\n```bash\r\nversion_name.rb\r\n```\r\n\r\nwhere `version` is an integer and `name` is a string which should be a very brief description of what the migration does. Examples:\r\n```bash\r\n001_create_films.rb\r\n002_add_director_to_films.rb\r\n...\r\n015_foo.rb\r\n016_bar.rb\r\n```\r\nThis guide is based on https://github.com/jeremyevans/sequel/blob/master/doc/migration.rdoc\r\n\r\n# License\r\nCopyright (c) 2018 Alfredo Ramírez.\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfredormz%2Fpg-schema-migration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfredormz%2Fpg-schema-migration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfredormz%2Fpg-schema-migration/lists"}