Sha256: 51031484c48da11d76b463f3ee848d814acfea70b36c42a682a361b655af0639

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literals: true

require "jobshop/helpers/migration.rb"

class CreateRoles < ActiveRecord::Migration[5.2]
  include Jobshop::Helpers::Migration

  def change # rubocop:disable Metrics/MethodLength
    create_table :jobshop_roles, id: false do |t|
      t.uuid :organization_id, null: false
      t.uuid :role_id, null: false, default: "gen_random_uuid()"
      t.index %i[ organization_id role_id ], unique: true,
        name: :idx_jobshop_roles_pkey

      t.citext :name
      t.index %i[ organization_id name ], unique: true

      t.timestamps
    end

    idx_table_name_pkey :jobshop_roles
    fk_organization_id :jobshop_roles

    create_table :jobshop_role_assignments, id: false do |t|
      t.uuid :organization_id, null: false
      t.uuid :person_id, null: false
      t.uuid :role_id, null: false

      t.index %i[ organization_id person_id role_id ], unique: true,
        name: :jobshop_role_assignment_user_roles_ckey
      t.index %i[ organization_id role_id person_id ], unique: true,
        name: :jobshop_role_assignment_role_users_ckey

      t.timestamps
    end

    fk_organization_id :jobshop_role_assignments
    foreign_key :jobshop_role_assignments, :jobshop_roles,
      %i[ organization_id role_id ]
    foreign_key :jobshop_role_assignments, :jobshop_people,
      %i[ organization_id person_id ]

    create_table :jobshop_abilities, id: :uuid, default: "gen_random_uuid()" do |t|
      t.uuid :organization_id, null: false
      t.uuid :resource_id
      t.string :resource_class, null: false
      t.integer :action
      t.index %i[ organization_id resource_class action resource_id ],
        unique: true, name: :idx_jobshop_abilities_secondary_key
    end

    fk_organization_id :jobshop_abilities
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.163 db/migrate/20171216023018_create_roles.rb