Imrpove migrations
This commit is contained in:
1 parent
f386499d2f
commit
4f28a59c7e
7 files changed
+187
-88
No files matched your search
@@ -1,19 +1,68 @@
|
||||
Sequel.migration do
|
||||
up do
|
||||
create_table(:account_statuses) do
|
||||
Integer :id, primary_key: true
|
||||
String :name, null: false, unique: true
|
||||
end
|
||||
|
||||
from(:account_statuses).import(
|
||||
[:id, :name],
|
||||
[
|
||||
[1, "Unverified"],
|
||||
[2, "Verified"],
|
||||
[3, "Closed"]
|
||||
]
|
||||
)
|
||||
|
||||
db = self
|
||||
|
||||
create_table(:accounts) do
|
||||
primary_key :id, type: :Bignum
|
||||
|
||||
foreign_key :status_id, :account_statuses,
|
||||
null: false,
|
||||
default: 1
|
||||
|
||||
String :email, null: false
|
||||
|
||||
index :email, unique: true
|
||||
if db.supports_partial_indexes?
|
||||
index :email, unique: true, where: { status_id: [1, 2] }
|
||||
else
|
||||
index :email, unique: true
|
||||
end
|
||||
end
|
||||
|
||||
create_table(:account_password_hashes) do
|
||||
foreign_key :id, :accounts, primary_key: true, type: :Bignum
|
||||
foreign_key :id, :accounts,
|
||||
primary_key: true,
|
||||
type: :Bignum
|
||||
|
||||
String :password_hash, null: false
|
||||
end
|
||||
|
||||
create_table(:account_verification_keys) do
|
||||
foreign_key :id, :accounts,
|
||||
primary_key: true,
|
||||
type: :Bignum
|
||||
|
||||
String :key, null: false
|
||||
|
||||
DateTime :requested_at,
|
||||
null: false,
|
||||
default: Sequel::CURRENT_TIMESTAMP
|
||||
|
||||
DateTime :email_last_sent,
|
||||
null: false,
|
||||
default: Sequel::CURRENT_TIMESTAMP
|
||||
end
|
||||
end
|
||||
|
||||
down do
|
||||
drop_table(:account_password_hashes, :accounts)
|
||||
drop_table(
|
||||
:account_verification_keys,
|
||||
:account_password_hashes,
|
||||
:accounts,
|
||||
:account_statuses
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user