{"id":26274424,"url":"https://github.com/shivam091/postgresql_adapter_extensions","last_synced_at":"2025-10-05T06:59:00.978Z","repository":{"id":281819857,"uuid":"946464696","full_name":"shivam091/postgresql_adapter_extensions","owner":"shivam091","description":"PostgreSQL Adapter Extensions for ActiveRecord","archived":false,"fork":false,"pushed_at":"2025-08-13T22:35:58.000Z","size":99,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-20T21:22:14.625Z","etag":null,"topics":["postgresql","sequences"],"latest_commit_sha":null,"homepage":"https://shivam091.github.io/postgresql_adapter_extensions/","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/shivam091.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2025-03-11T07:19:51.000Z","updated_at":"2025-03-27T10:18:28.000Z","dependencies_parsed_at":"2025-05-05T22:58:00.203Z","dependency_job_id":"b6d804bd-0db1-4293-982b-0e722e4fa572","html_url":"https://github.com/shivam091/postgresql_adapter_extensions","commit_stats":null,"previous_names":["shivam091/postgresql_adapter_extensions"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/shivam091/postgresql_adapter_extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivam091%2Fpostgresql_adapter_extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivam091%2Fpostgresql_adapter_extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivam091%2Fpostgresql_adapter_extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivam091%2Fpostgresql_adapter_extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shivam091","download_url":"https://codeload.github.com/shivam091/postgresql_adapter_extensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivam091%2Fpostgresql_adapter_extensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278420211,"owners_count":25983813,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["postgresql","sequences"],"created_at":"2025-03-14T09:19:37.872Z","updated_at":"2025-10-05T06:59:00.949Z","avatar_url":"https://github.com/shivam091.png","language":"Ruby","readme":"# PostgreSQLAdapterExtensions\n\nPostgreSQL Adapter Extensions for ActiveRecord.\n\n`postgresql_adapter_extensions` is a Ruby gem that extends the `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter`\nto add additional sequence-related methods for managing PostgreSQL sequences in a Rails application.\n\n[![Ruby](https://github.com/shivam091/postgresql_adapter_extensions/actions/workflows/main.yml/badge.svg)](https://github.com/shivam091/postgresql_adapter_extensions/actions/workflows/main.yml)\n[![Gem Version](https://badge.fury.io/rb/postgresql_adapter_extensions.svg)](https://badge.fury.io/rb/postgresql_adapter_extensions)\n[![Gem Downloads](https://img.shields.io/gem/dt/postgresql_adapter_extensions.svg)](http://rubygems.org/gems/postgresql_adapter_extensions)\n[![Maintainability](https://api.codeclimate.com/v1/badges/be55ce822a1f617f6bdd/maintainability)](https://codeclimate.com/github/shivam091/postgresql_adapter_extensions/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/be55ce822a1f617f6bdd/test_coverage)](https://codeclimate.com/github/shivam091/postgresql_adapter_extensions/test_coverage)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/shivam091/postgresql_adapter_extensions/blob/main/LICENSE.md)\n\n[Harshal V. Ladhe, Master of Computer Science.](https://shivam091.github.io)\n\n## Introduction\n\nThis gem provides easy-to-use methods to create, alter, and drop sequences, which can be useful for handling\nauto-incrementing IDs and other sequence-based logic in your database.\n\n## Minimum Requirements\n\n* Ruby 3.3+ ([Download Ruby](https://www.ruby-lang.org/en/downloads/branches/))\n* Rails 8.0.0+ ([RubyGems - Rails Versions](https://rubygems.org/gems/rails/versions))\n* ActiveRecord 8.0.0+ (comes with Rails)\n\n## Installation\n\nTo use `postgresql_adapter_extensions` in your Rails application, add the following line to your Gemfile:\n\n```ruby\ngem \"postgresql_adapter_extensions\"\n```\n\nAnd then execute:\n\n`$ bundle install`\n\nOr otherwise simply install it yourself as:\n\n`$ gem install postgresql_adapter_extensions`\n\n## Usage\n\n### create_sequence\n\nThe `create_sequence` method allows you to create a new sequence in your PostgreSQL database with customizable options. A sequence is typically used to auto-generate unique values for primary keys or other incrementing columns.\n\n```ruby\ncreate_sequence(name, options = {})\n```\n\n**Create a sequence with default options:**\n\n```ruby\ncreate_sequence(:order_id_seq)\n```\n\n**Create a sequence starting from 1000 with an increment of 5:**\n\n```ruby\ncreate_sequence(:order_id_seq, start: 1000, increment_by: 5)\n```\n\n**Create a cyclic sequence with a maximum value of 5000:**\n\n```ruby\ncreate_sequence(:order_id_seq, cycle: true, maxvalue: 5000)\n```\n\n**Create a sequence owned by a specific table and column:**\n\n```ruby\ncreate_sequence(:order_id_seq, owned_by: \"orders.id\")\n```\n\n### alter_sequence\n\nThe `alter_sequence` method allows you to modify an existing sequence in your PostgreSQL database.\nYou can change various attributes of the sequence, such as its increment, start value, maximum value,\ncycle behavior, and ownership.\n\n```ruby\nalter_sequence(name, options = {})\n```\n\n**Modify the increment value of a sequence:**\n\n```ruby\nalter_sequence(:order_id_seq, increment_by: 10)\n```\n\n**Restart a sequence at a specific value:**\n\n```ruby\nalter_sequence(:order_id_seq, restart_with: 2000)\n```\n\n**Set a minimum and maximum value for a sequence:**\n\n```ruby\nalter_sequence(:order_id_seq, minvalue: 500, maxvalue: 10000)\n```\n\n**Make a sequence cycle when it reaches the maximum value:**\n\n```ruby\nalter_sequence(:order_id_seq, cycle: true)\n```\n\n**Remove the cycle behavior from a sequence:**\n\n```ruby\nalter_sequence(:order_id_seq, cycle: false)\n```\n\n**Change the owner of a sequence to a specific table column:**\n\n```ruby\nalter_sequence(:order_id_seq, owned_by: \"orders.id\")\n```\n\nThis method provides flexibility in managing sequences dynamically in your Rails\napplication, ensuring that sequence-related database behavior can be modified as needed.\n\n### drop_sequence\n\nThe `drop_sequence` method allows you to drop an existing sequence from your PostgreSQL database, with options to control its behavior.\n\n```ruby\ndrop_sequence(name, options = {})\n```\n\n**Drop a sequence without additional options:**\n\n ```ruby\ndrop_sequence(:order_id_seq)\n```\n\n**Drop a sequence if it exists:**\n\n```ruby\ndrop_sequence(:order_id_seq, if_exists: true)\n```\n\n**Drop a sequence and all dependent objects:**\n\n```ruby\ndrop_sequence(:order_id_seq, drop_behavior: :cascade)\n```\n\n**Drop a sequence but prevent deletion if dependencies exist:**\n\n```ruby\ndrop_sequence(:order_id_seq, drop_behavior: :restrict)\n```\n\n### rename_sequence\n\nThe `rename_sequence` method allows you to rename an existing sequence in your PostgreSQL database.\n\n```ruby\nrename_sequence(name, options = {})\n```\n\n**Rename a sequence:**\n\n```ruby\nrename_sequence(:order_id_seq, to: :new_order_id_seq)\n```\n\n**Rename a sequence only if it exists:**\n\n```ruby\nrename_sequence(:order_id_seq, to: :new_order_id_seq, if_exists: true)\n```\n\n## PostgreSQL Setup for Contributors\n\nIf you're contributing to this gem and need to set up PostgreSQL for local development or testing,\nyou can use the provided setup script. This script will help you create the necessary PostgreSQL\nuser and database for testing.\n\n### Running the Setup Script\n\n1. **Clone the repository** and navigate to the root directory of the gem.\n2. Make sure you have PostgreSQL installed and running on your machine.\n3. Run the script using the following command:\n\n   `$ ./bin/setup_postgresql.sh`\n\n   By default, the script will use the following values unless environment variables are set:\n\n   1. Database Name: `rails_test`\n   2. Username: `rails`\n   3. Password: `password`\n\n4. If you want to override these defaults, set the environment variables before running the script:\n\n   `$ POSTGRES_DB=rails_test POSTGRES_USER=rails POSTGRES_PASSWORD=password ./bin/setup_postgresql.sh`\n\n5. The script will:\n\n   - Check if the specified PostgreSQL user exists, creating it if necessary.\n   - Check if the specified database exists, creating it if necessary.\n   - Grant the required privileges to the user for the database.\n\n***Note: This script is only required if you're contributing to the development of the gem or testing locally. It is not required for end users of the gem.***\n\n## Tests\n\nThe gem includes RSpec tests to verify that the sequence methods behave as expected.\n\n### Running the Tests\n\nTo run the tests, you need to install the required dependencies first:\n\n`$ bundle install`\n\nThen, run the tests with:\n\n`$ bundle exec rspec`\n\nThe tests are located in the `spec/` directory and verify the behavior of `create_sequence`,\n`alter_sequence`, and `drop_sequence` methods.\n\n## Contributing\n\nContributions to this project are welcomed! To contribute:\n\n1. Fork this repository\n2. Create a new branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am \"Add some feature\"`)\n4. Push the changes to your branch (`git push origin my-new-feature`)\n5. Create new **Pull Request**\n\n## License\n\nCopyright 2025 [Harshal V. LADHE](https://shivam091.github.io), Released under the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivam091%2Fpostgresql_adapter_extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshivam091%2Fpostgresql_adapter_extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivam091%2Fpostgresql_adapter_extensions/lists"}