-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More effective way to store uuids (#8)
* More effective way to store uuids * Add github actions * More helpers for automated v1 migrations * Fixes for ruby 3.1
- Loading branch information
Showing
18 changed files
with
321 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Build + publish | ||
|
||
on: | ||
push: | ||
tags: [ v* ] | ||
jobs: | ||
build: | ||
name: Build + Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Release Gem | ||
if: contains(github.ref, 'refs/tags/v') | ||
uses: cadwallion/publish-rubygems-action@master | ||
env: | ||
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}} | ||
RELEASE_COMMAND: bundle exec rake release | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# - name: Set up Ruby | ||
# uses: ruby/setup-ruby@v1 | ||
# with: | ||
# ruby-version: .ruby-version | ||
# bundler-cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake | ||
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby | ||
|
||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ '*' ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }}-latest | ||
strategy: | ||
matrix: | ||
os: [ubuntu, macos] | ||
ruby-version: ['2.7', '3.0', '3.1'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Ruby | ||
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, | ||
# change this to (see https://github.com/ruby/setup-ruby#versioning): | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
- name: Run rubocop | ||
run: bundle exec rubocop | ||
- name: Run tests | ||
run: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/.history/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'uuidable' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module Uuidable | ||
COLUMN_NAME = :uuid | ||
COLUMN_TYPE = :binary | ||
COLUMN_OPTIONS = { limit: 36, null: false }.freeze | ||
COLUMN_OPTIONS = { limit: 16, null: false }.freeze | ||
INDEX_OPTIONS = { unique: true }.freeze | ||
|
||
# Module adds method to table definition | ||
module TableDefinition | ||
def uuid(opts = {}) | ||
def uuid(column_name = COLUMN_NAME, **opts) | ||
index_opts = opts.delete(:index) | ||
index_opts = {} if index_opts.nil? | ||
|
||
column_name = opts.delete(:column_name) || COLUMN_NAME | ||
column_name ||= opts.delete(:column_name) | ||
|
||
column column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts) | ||
index column_name, INDEX_OPTIONS.merge(index_opts) if index_opts | ||
column column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts) | ||
index column_name, **INDEX_OPTIONS.merge(index_opts) if index_opts | ||
end | ||
end | ||
|
||
# Module adds method to alter table migration | ||
module Migration | ||
def add_uuid_column(table_name, opts = {}) | ||
def add_uuid_column(table_name, column_name = COLUMN_NAME, **opts) | ||
index_opts = opts.delete(:index) | ||
index_opts = {} if index_opts == true | ||
|
||
column_name = opts.delete(:column_name) || COLUMN_NAME | ||
column_name ||= opts.delete(:column_name) | ||
|
||
add_column table_name, column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts) | ||
add_column table_name, column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts) | ||
|
||
add_uuid_index(table_name, index_opts.merge(column_name: column_name)) if index_opts | ||
end | ||
|
||
def add_uuid_index(table_name, opts = {}) | ||
column_name = opts.delete(:column_name) || COLUMN_NAME | ||
|
||
add_index table_name, column_name, INDEX_OPTIONS.merge(opts) | ||
add_index table_name, column_name, **INDEX_OPTIONS.merge(opts) | ||
end | ||
end | ||
end | ||
|
||
if defined? ActiveRecord::ConnectionAdapters::TableDefinition | ||
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Uuidable::TableDefinition | ||
ActiveRecord::ConnectionAdapters::TableDefinition.include Uuidable::TableDefinition | ||
end | ||
|
||
ActiveRecord::Migration.send :include, Uuidable::Migration if defined? ActiveRecord::Migration | ||
ActiveRecord::Migration.include Uuidable::Migration if defined? ActiveRecord::Migration |
Oops, something went wrong.