0.0
The project is in a healthy, maintained state
Override migration methods to support UUID/ULID columns without having to be explicit about it.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 8.0.0
 Project Readme

ar-sqlite-uuid

Tests Gem Gem

Override migration methods to support UUID/ULID columns without having to be explicit about it.

Installation

$ gem install ar-sqlite-uuid

Or add the following line to your project's Gemfile:

$ bundle add ar-sqlite-uuid

Also, make sure the extension is loaded. I recommend using sqlpkg. Then you can install the extension you want to use:

$ sqlpkg install asg017/ulid
$ sqlpkg install sqlite/uuid

To load the extension into your sqlite database,

Usage

On your gemfile, you must specify which extension you want to use by loading either ar-sqlite-uuid or ar-sqlite-ulid.

source "https://rubygems.org"

# This will use the `sqlite/uuid` extension.
gem "ar-sqlite-uuid"

# This will use the `asg017/ulid` extension.
gem "ar-sqlite-uuid", require: "ar-sqlite-ulid"

Alternatively, you can also manually define the function that will be used:

# file: config/initialize/active_record.rb

# use ulid
AR::UUID.default_function = "ulid()"

# use ulid with a static prefix
AR::UUID.default_function = "ulid_with_prefix('myapp')"

# use ulid with a dynamic prefix.
# By default it uses the table name, but you can override it by passing a
# `:prefix` key to `t.primary_key` or `create_table`.
AR::UUID.default_function = "ulid_with_prefix('%{prefix}')"

# use uuid
AR::UUID.default_function = "uuid()"

When you create a new table, the id column will be defined as TEXT, using the defined function as the default value.

create_table :users
add_reference :posts, :users

create_table :posts do |t|
  t.belongs_to :user
  # or
  t.references :user
end

If you need an integer column, specify the type manually.

create_table :users,  do |t|
  t.column :position, :bigserial, null: false
end

Maintainer

Contributors

Contributing

For more details about how to contribute, please read https://github.com/fnando/ar-sqlite-uuid/blob/main/CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License. A copy of the license can be found at https://github.com/fnando/ar-sqlite-uuid/blob/main/LICENSE.md.

Code of Conduct

Everyone interacting in the ar-sqlite-uuid project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.