{"id":13394955,"url":"https://github.com/lfittl/activerecord-clean-db-structure","last_synced_at":"2025-05-15T10:07:05.556Z","repository":{"id":54232889,"uuid":"81719490","full_name":"lfittl/activerecord-clean-db-structure","owner":"lfittl","description":"Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)","archived":false,"fork":false,"pushed_at":"2025-04-09T16:21:16.000Z","size":93,"stargazers_count":149,"open_issues_count":7,"forks_count":38,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T16:57:23.198Z","etag":null,"topics":["activerecord","database","postgres","postgresql","rails"],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lfittl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2017-02-12T10:53:06.000Z","updated_at":"2025-04-04T20:54:31.000Z","dependencies_parsed_at":"2024-01-13T20:57:17.805Z","dependency_job_id":"d4297e66-cc6b-4519-a4f1-e53c568f979a","html_url":"https://github.com/lfittl/activerecord-clean-db-structure","commit_stats":{"total_commits":60,"total_committers":12,"mean_commits":5.0,"dds":0.6333333333333333,"last_synced_commit":"b5532bb0e07f7865c5b6c8e6792d196e6f2c1ef2"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfittl%2Factiverecord-clean-db-structure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfittl%2Factiverecord-clean-db-structure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfittl%2Factiverecord-clean-db-structure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfittl%2Factiverecord-clean-db-structure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfittl","download_url":"https://codeload.github.com/lfittl/activerecord-clean-db-structure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"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","database","postgres","postgresql","rails"],"created_at":"2024-07-30T17:01:37.349Z","updated_at":"2025-05-15T10:07:00.542Z","avatar_url":"https://github.com/lfittl.png","language":"PLpgSQL","funding_links":[],"categories":["PLpgSQL","Ruby","Gems"],"sub_categories":["Database Integrity and Data Consistency"],"readme":"## activerecord-clean-db-structure [ ![](https://img.shields.io/gem/v/activerecord-clean-db-structure.svg)](https://rubygems.org/gems/activerecord-clean-db-structure) [ ![](https://img.shields.io/gem/dt/activerecord-clean-db-structure.svg)](https://rubygems.org/gems/activerecord-clean-db-structure)\n\nEver been annoyed at a constantly changing `db/structure.sql` file when using ActiveRecord and Postgres?\n\nSpent hours trying to decipher why that one team member keeps changing the file?\n\nThis library is here to help!\n\nIt cleans away all the unnecessary output in the file every time its updated automatically. This helps avoid merge conflicts, as well as increase readability.\n\n## Installation\n\nAdd the following to your Gemfile:\n\n```ruby\ngem 'activerecord-clean-db-structure'\n```\n\nThis will automatically hook the library into your `rake db:migrate` task.\n\n## Supported Rails versions\n\nWhilst there is no reason this shouldn't work on earlier versions, this has only been tested on Rails 4.2 and newer.\n\nIt also assumes you use ActiveRecord with PostgreSQL - other ORMs or databases are not supported.\n\n## Caveats\n\nCurrently the library assumes all your `id` columns are either SERIAL, BIGSERIAL or uuid. It also assumes the `id` is the primary key.\n\nMulti-column primary keys, as well as tables that don't have `id` as the primary key are not supported right now, and might lead to wrong output.\n\nYou can disable this part of the _cleaning_ process in your `config/environments/\u003cenvironment\u003e.rb` (or `config/application.rb`):\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.ignore_ids = true\nend\n```\n\n## Other options\n\n### indexes_after_tables\n\nYou can optionally have indexes following the respective tables setting `indexes_after_tables`:\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.indexes_after_tables = true\nend\n```\n\nWhen it is enabled the structure looks like this:\n\n```sql\nCREATE TABLE public.users (\n    id SERIAL PRIMARY KEY,\n    tenant_id integer,\n    email text NOT NULL\n);\n\nCREATE INDEX index_users_on_tentant_id ON public.users USING btree (tenant_id);\nCREATE UNIQUE INDEX index_users_on_email ON public.users USING btree (email);\n```\n\n### order_column_definitions\n\nTo enable sorting the table column definitions alphabetically, discarding the actual order provided by `pg_dump`, set `order_column_definitions`:\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.order_column_definitions = true\nend\n```\n\n### order_schema_migrations_values\n\nYou can have the schema_migrations values reorganized to prevent merge conflicts by setting `order_schema_migrations_values`:\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.order_schema_migrations_values = true\nend\n```\n\nWhen it is enabled the values are ordered chronological and the semicolon is placed on a separate line:\n\n```sql\nINSERT INTO \"schema_migrations\" (version) VALUES\n ('20190503120501')\n,('20190508123941')\n,('20190508132644')\n;\n```\n\n### keep_extensions\n\nBy default the gem will remove [some extensions](https://github.com/ghiculescu/activerecord-clean-db-structure/blob/c9551391476a5e7a08ff314501af89baddcf669a/lib/activerecord-clean-db-structure/clean_dump.rb#L24) that typically aren't needed in structure dumps. You can choose to keep all, or just some, of those extensions:\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.keep_extensions = :all\n\n  # This does the same thing as :all. You can choose which optional extensions to keep.\n  config.activerecord_clean_db_structure.keep_extensions = ['pg_stat_statements', 'pg_buffercache']\nend\n```\n\n### ignore_schmeas\n\nYou can ignore specific schemas, for example when dumping from a database copy that is integrated with pganalyze and has helper functions:\n\n```ruby\nRails.application.configure do\n  config.activerecord_clean_db_structure.ignore_schemas = ['pganalyze']\nend\n```\n\n## Authors\n\n* [Lukas Fittl](https://github.com/lfittl)\n\n## License\n\nCopyright (c) 2017, Lukas Fittl\u003cbr\u003e\nactiverecord-clean-db-structure is licensed under the 3-clause BSD license, see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfittl%2Factiverecord-clean-db-structure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfittl%2Factiverecord-clean-db-structure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfittl%2Factiverecord-clean-db-structure/lists"}