{"id":13878715,"url":"https://github.com/nepalez/pg_trunk","last_synced_at":"2025-04-09T18:17:54.391Z","repository":{"id":44765499,"uuid":"435623791","full_name":"nepalez/pg_trunk","owner":"nepalez","description":"Empower PostgreSQL migrations in Rails app","archived":false,"fork":false,"pushed_at":"2022-01-26T08:22:12.000Z","size":366,"stargazers_count":133,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T18:17:49.970Z","etag":null,"topics":["activerecord","postgresql","rails","ruby"],"latest_commit_sha":null,"homepage":"","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/nepalez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-06T19:36:27.000Z","updated_at":"2025-03-09T22:57:57.000Z","dependencies_parsed_at":"2022-08-21T00:50:51.344Z","dependency_job_id":null,"html_url":"https://github.com/nepalez/pg_trunk","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nepalez%2Fpg_trunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nepalez%2Fpg_trunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nepalez%2Fpg_trunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nepalez%2Fpg_trunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nepalez","download_url":"https://codeload.github.com/nepalez/pg_trunk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085328,"owners_count":21045139,"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":["activerecord","postgresql","rails","ruby"],"created_at":"2024-08-06T08:01:57.526Z","updated_at":"2025-04-09T18:17:54.367Z","avatar_url":"https://github.com/nepalez.png","language":"Ruby","readme":"# PGTrunk\n\nEmpower PostgreSQL migrations in Rails app\n\n\u003ca href=\"https://evilmartians.com/\"\u003e\n\u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\" alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\u003c/a\u003e\n\n[![Gem Version][gem-badger]][gem]\n[![Build Status][build-badger]][build]\n\nPGTrunk adds methods to `ActiveRecord::Migration` to create and manage\nvarious PostgreSQL objects (like views, functions, triggers, statistics, types etc.)\nin Rails.\n\nThis gem is greatly influenced by the [Scenic], [F(x)] and [ActiveRecord::PostgtresEnum] projects\nbut takes some steps further.\n\nIn addition to support of different objects, we are solving a problem of interdependency between them.\nFor example, you can create a table, then a function using its type as an argument,\nthen check constraint and index using the function:\n\n```ruby\ncreate_table \"users\" do |t|\n  t.text \"first_name\"\n  t.text \"last_name\"\nend\n\n# depends on the `users` table\ncreate_function \"full_name(u users) text\" do |f|\n  f.volatility :immutable\n  f.strict true\n  f.parallel :safe\n  f.body \u003c\u003c~SQL.strip\n    string_trim(\n      SELECT COALESCE(u.first_name, '') + '.' + COALESCE(u.second_name, ''),\n      '.'\n    )\n  SQL\nend\n\n# both objects below depend on the `users` and `full_name(users)`\n# so they couldn't be placed inside the `create_table` definition in the schema.\n\ncreate_index \"users\", \"full_name(users.*)\", unique: true\n\n# users.full_name is the PostgreSQL alternative syntax for the `full_name(users.*)`\ncreate_check_constraint \"users\", \"length(users.full_name) \u003e 0\", name: \"full_name_present\"\n```\n\nNotice, that we had to separate definitions of indexes and check constraints from tables,\nbecause there can be other objects (like functions or types) squeezing between them.\n\nAnother difference from aforementioned gems is that we explicitly register\nall objects created by migrations in the special table (`pg_trunk`).\nThis let us distinct objects created by \"regular\" migration from temporary ones\nadded manually and exclude the latter from the schema. We bind any object\nto a particular version of migration which added it. That's how only those\nobjects that belong to the current branch are dumped into the `schema.rb`.\n\nAs of today we support creation, modification and dropping the following objects:\n\n- tables\n- indexes\n- foreign keys (including multi-column ones)\n- check constraints\n- views\n- materialized views\n- functions\n- procedures\n- triggers\n- custom statistics\n- enumerable types\n- composite types\n- domains types\n- rules\n- sequences\n\nFor `tables` and `indexes` we reuse the ActiveRecord's native methods.\nFor `check constraints` and `foreign keys` we support both the native definitions inside the table\nand standalone methods (like `create_foreign_key`) with additional features.\nThe other methods are implemented from scratch.\n\nIn the future other objects like aggregate functions, range types, operators, collations, and more\nwill be supported.\n\nFrom now and on we support all versions of PostgreSQL since v10.\n\nThe gem is targeted to support PostgreSQL-specific features, that's why we won't provide adapters to other databases like [Scenic] does.\n\n## Documentation\n\nThe gem provides a lot of additional methods to create, rename, change a drop various objects.\nYou can find the necessary details [here](https://rubydoc.info/gems/pg_trunk/ActiveRecord/Migration).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'pg_trunk'\n```\n\nAnd then execute:\n\n```shell\n$ bundle install\n```\n\nOr install it yourself as:\n\n```shell\n$ gem install pg_trunk\n```\n\nAdd the line somewhere in your ruby code:\n\n```ruby\nrequire \"pg_trunk\"\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at `https://github.com/nepalez/pg_trunk`.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License].\n\n[build-badger]: https://github.com/nepalez/pg_trunk/workflows/CI/badge.svg\n[build]: https://github.com/nepalez/pg_trunk/actions?query=workflow%3ACI+branch%3Amaster\n[gem-badger]: https://img.shields.io/gem/v/pg_trunk.svg?style=flat\n[gem]: https://rubygems.org/gems/pg_trunk\n[MIT License]: https://opensource.org/licenses/MIT\n[Scenic]: https://github.com/scenic-views/scenic\n[F(x)]: https://github.com/teoljungberg/fx\n[ActiveRecord::PostgtresEnum]: https://github.com/bibendi/activerecord-postgres_enum\n[wiki]: https://github.com/nepalez/pg_trunk/wiki\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnepalez%2Fpg_trunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnepalez%2Fpg_trunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnepalez%2Fpg_trunk/lists"}