Sha256: 84288d5af44a1b3ee2ee804c7b42bb4af52fad499fc38539cb1657ed6c62bfcf

Contents?: true

Size: 894 Bytes

Versions: 1

Compression:

Stored size: 894 Bytes

Contents

class CreateMembers < ActiveRecord::Migration[7.1]
  def change
    create_table :members do |t|
      t.string :public_uid, index: { unique: true }

      t.references :user, null: true, foreign_key: true # nullable for invitations
      t.references :account, null: false, foreign_key: true
      t.references :invited_by, foreign_key: { to_table: :members }, null: true # null for owner

      ## Is the user an owner of the account?
      t.boolean :owner, default: false, null: false

      ## Invitations fields
      t.string :invitation_email
      t.string :invitation_token
      t.datetime :invitation_sent_at
      t.datetime :invitation_accepted_at

      t.timestamps
    end

    add_index :members, :invitation_token, unique: true
    add_index :members, [ :account_id, :user_id ], unique: true
    add_index :members, [ :account_id, :invitation_email ], unique: true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kiqr-0.1.0.alpha1 db/migrate/20240325142603_create_members.rb