{"id":13468957,"url":"https://github.com/braintree/pg_column_byte_packer","last_synced_at":"2025-06-25T10:40:34.283Z","repository":{"id":44718065,"uuid":"298683281","full_name":"braintree/pg_column_byte_packer","owner":"braintree","description":"Auto-order table columns for optimize disk space usage","archived":false,"fork":false,"pushed_at":"2025-02-04T15:42:49.000Z","size":77,"stargazers_count":83,"open_issues_count":5,"forks_count":10,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-04T20:17:32.818Z","etag":null,"topics":["hacktoberfest"],"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/braintree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2020-09-25T21:29:59.000Z","updated_at":"2025-02-04T15:26:35.000Z","dependencies_parsed_at":"2025-02-04T16:34:32.998Z","dependency_job_id":null,"html_url":"https://github.com/braintree/pg_column_byte_packer","commit_stats":{"total_commits":72,"total_committers":5,"mean_commits":14.4,"dds":0.4722222222222222,"last_synced_commit":"900dac01a58c37108198d95888db7974a29f1655"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braintree%2Fpg_column_byte_packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braintree%2Fpg_column_byte_packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braintree%2Fpg_column_byte_packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braintree%2Fpg_column_byte_packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/braintree","download_url":"https://codeload.github.com/braintree/pg_column_byte_packer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245597393,"owners_count":20641869,"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":["hacktoberfest"],"created_at":"2024-07-31T15:01:22.699Z","updated_at":"2025-03-26T05:31:26.814Z","avatar_url":"https://github.com/braintree.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# PostgreSQL Column Byte Packer\n\n[![Build Status](https://github.com/braintree/pg_column_byte_packer/actions/workflows/ci.yml/badge.svg)](https://github.com/braintree/pg_column_byte_packer/actions/workflows/ci.yml?query=branch%3Amaster+)\n\ntl;dr: Provides facilities for laying out table column order to optimize for disk space usage both in ActiveRecord migrations and `pg_dump` generated SQL schema files. The general idea and relevant PostgreSQL internals are described in [On Rocks and Sand](https://www.2ndquadrant.com/en/blog/on-rocks-and-sand/).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'pg_column_byte_packer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install pg_column_byte_packer\n\n## Usage\n\nThere are two ways you can use this library to byte-pack your tables' column layout:\n\n### Re-ordering columns using ActiveRecord migrations\n\nLoading the library automatically patches ActiveRecord's table creation tree walker to automatically re-order columns by alignment size. Therefore all `create_table` calls in ActiveRecord migrations executed after loading the gem will be byte-packing optimized.\n\nNote: Because you need the full table definition to re-order columns, the most benefit occurs when the full table is created in one step (rather than added onto with repeated `add_column` migrations).\n\n### Re-ordering SQL structure files (from `pg_dump`)\n\nActiveRecord defaults to saving your application's database structure to a `schema.rb` file (which is essentially all of the ActiveRecord migrations commands you'd need to generate the current state of the database). However you can also configure it to save a copy of the database structure in SQL format by setting `config.active_record.schema_format = :sql` in your `config/application.rb` file. With this configuration (and running against a PostgreSQL database) ActiveRecord executes the `pg_dump` utility (included in the PostgreSQL client tools) against your database to generate a `structure.sql` file.\n\nIf you have an existing `structure.sql` file (or any structure-only file generated by `pg_dump`), you can update that file to have byte-packed `CREATE TABLE` statements with the following:\n\n```ruby\nPgColumnBytePacker::PgDump.sort_columns_for_definition_file(\n  \"\u003cpath to structure.sql file\u003e\",\n  connection: ActiveRecord::Base.connection\n)\n```\n\nNote: an ActiveRecord connection object is required so that the library can properly determine the data types (and their respective alignment requirements) and column metadata (e.g., `DEFAULT` and `NOT NULL`).\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. This project uses Appraisal to test against multiple versions of ActiveRecord; you can run the tests against all supported version with `bundle exec appraisal rspec`.\n\nRunning tests will automatically create a test database in the locally running Postgres server. You can find the connection parameters in `spec/spec_helper.rb`, but setting the environment variables `PGHOST`, `PGPORT`, `PGUSER`, and `PGPASSWORD` will override the defaults.\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`, commit the change, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). To ignore local changes (say to `.ruby-version`) you can do `rake build release:source_control_push release:rubygem_push`.\n\nNote: if while releasing the gem you get the error ``Your rubygems.org credentials aren't set. Run `gem push` to set them.`` you can more simply run `gem signin`.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraintree%2Fpg_column_byte_packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbraintree%2Fpg_column_byte_packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraintree%2Fpg_column_byte_packer/lists"}