2021-02-04 21:08:20 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class CreateUserRolesAndAssignments < ActiveRecord::Migration[6.1]
|
|
|
|
def change
|
|
|
|
create_table :user_roles do |t|
|
|
|
|
t.string :name
|
2021-02-18 16:54:53 +08:00
|
|
|
t.boolean :predefined, default: false
|
2021-02-04 21:08:20 +08:00
|
|
|
t.string :permissions, array: true, default: []
|
|
|
|
t.references :created_by, foreign_key: { to_table: :users }, null: false
|
|
|
|
t.references :last_modified_by, foreign_key: { to_table: :users }, null: false
|
|
|
|
|
|
|
|
t.timestamps
|
|
|
|
end
|
|
|
|
|
|
|
|
create_table :user_assignments do |t|
|
|
|
|
t.references :assignable, polymorphic: true, null: false
|
|
|
|
t.references :user, foreign_key: true, null: false
|
|
|
|
t.references :user_role, foreign_key: true, null: false
|
|
|
|
t.references :assigned_by, foreign_key: { to_table: :users }, null: false
|
|
|
|
|
|
|
|
t.timestamps
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|