https://github.com/katzer/primary_key_type_replacer
ActiveRecord plugin to replace the primary key type
https://github.com/katzer/primary_key_type_replacer
Last synced: about 2 months ago
JSON representation
ActiveRecord plugin to replace the primary key type
- Host: GitHub
- URL: https://github.com/katzer/primary_key_type_replacer
- Owner: katzer
- License: gpl-2.0
- Created: 2013-08-11T11:32:25.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-11-18T08:46:22.000Z (over 12 years ago)
- Last Synced: 2025-01-28T12:41:56.200Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PrimaryKeyTypeReplacer
========================
ActiveRecord plugin to replace the primary key type of your database tables.
Should work with all supported activerecord adapters. Tested with
- mysql2
- sqlite3
- oracle_enhanced
by Sebastián Katzer ([github.com/katzer](https://github.com/katzer))
## Installation
Add this line to your application's Gemfile:
gem 'primary_key_type_replacer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install primary_key_type_replacer
## Usage
This gem adds the **singleton method** `replace_primary_key_type_with(_type_)` to your migration files.
See example below how to use it to disable the *autoincrement* feature.
```ruby
class CreateTableWithoutAutoIncrement < ActiveRecord::Migration
# Setzt den Typ des Primärschlüssels
replace_primary_key_type_with case adapter_name
when 'Mysql2'
'int(11) NOT NULL PRIMARY KEY'
when 'SQLite'
'INTEGER PRIMARY KEY NOT NULL'
end
def change
# Erstellt die Tabelle mit dem neuen Primärschlüsseltypen
create_table :table_without_auto_increment_id do |t|
# ...
end
end
end
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request