1
0
Fork 0

Merge migrations

This commit is contained in:
Alex Kotov 2019-07-22 09:01:01 +05:00
parent b07b7ba909
commit 347712e683
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 63 additions and 93 deletions

View file

@ -208,5 +208,67 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.2]
SQL SQL
end end
end end
constraint :accounts, :guest_token, <<~SQL
guest_token ~ '^[0-9a-f]{32}$'
SQL
constraint :accounts, :nickname, <<~SQL
length(nickname) BETWEEN 3 AND 36
AND
nickname ~ '^[a-z][a-z0-9]*(_[a-z0-9]+)*$'
SQL
constraint :accounts, :public_name, <<~SQL
public_name IS NULL
OR
length(public_name) BETWEEN 3 AND 255
AND
public_name !~ '^[[:space:]]*$'
SQL
constraint :accounts, :biography, <<~SQL
biography IS NULL
OR
length(biography) BETWEEN 3 AND 10000
AND
biography !~ '^[[:space:]]*$'
SQL
constraint :federal_subjects, :english_name, <<~SQL
length(english_name) BETWEEN 1 AND 255
AND
english_name !~ '^[[:space:]]{1,}'
AND
english_name !~ '[[:space:]]{1,}$'
SQL
constraint :federal_subjects, :native_name, <<~SQL
length(native_name) BETWEEN 1 AND 255
AND
native_name !~ '^[[:space:]]{1,}'
AND
native_name !~ '[[:space:]]{1,}$'
SQL
constraint :federal_subjects, :number, 'number > 0'
end
private
def constraint(table, name, check)
reversible do |dir|
dir.up do
execute <<~SQL
ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{check})
SQL
end
dir.down do
execute <<~SQL
ALTER TABLE #{table} DROP CONSTRAINT #{name}
SQL
end
end
end end
end end

View file

@ -1,49 +0,0 @@
# frozen_string_literal: true
class AddConstraintsToAccounts < ActiveRecord::Migration[6.0]
def change
constraint :accounts, :guest_token, <<~SQL
guest_token ~ '^[0-9a-f]{32}$'
SQL
constraint :accounts, :nickname, <<~SQL
length(nickname) BETWEEN 3 AND 36
AND
nickname ~ '^[a-z][a-z0-9]*(_[a-z0-9]+)*$'
SQL
constraint :accounts, :public_name, <<~SQL
public_name IS NULL
OR
length(public_name) BETWEEN 3 AND 255
AND
public_name !~ '^[[:space:]]*$'
SQL
constraint :accounts, :biography, <<~SQL
biography IS NULL
OR
length(biography) BETWEEN 3 AND 10000
AND
biography !~ '^[[:space:]]*$'
SQL
end
private
def constraint(table, name, check)
reversible do |dir|
dir.up do
execute <<~SQL
ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{check})
SQL
end
dir.down do
execute <<~SQL
ALTER TABLE #{table} DROP CONSTRAINT #{name}
SQL
end
end
end
end

View file

@ -1,41 +0,0 @@
# frozen_string_literal: true
class AddConstraintsToImportantTables < ActiveRecord::Migration[6.0]
def change
constraint :federal_subjects, :english_name, <<~SQL
length(english_name) BETWEEN 1 AND 255
AND
english_name !~ '^[[:space:]]{1,}'
AND
english_name !~ '[[:space:]]{1,}$'
SQL
constraint :federal_subjects, :native_name, <<~SQL
length(native_name) BETWEEN 1 AND 255
AND
native_name !~ '^[[:space:]]{1,}'
AND
native_name !~ '[[:space:]]{1,}$'
SQL
constraint :federal_subjects, :number, 'number > 0'
end
private
def constraint(table, name, check)
reversible do |dir|
dir.up do
execute <<~SQL
ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{check})
SQL
end
dir.down do
execute <<~SQL
ALTER TABLE #{table} DROP CONSTRAINT #{name}
SQL
end
end
end
end

View file

@ -1139,8 +1139,6 @@ SET search_path TO "$user", public;
INSERT INTO "schema_migrations" (version) VALUES INSERT INTO "schema_migrations" (version) VALUES
('20181129203927'), ('20181129203927'),
('20181130024918'), ('20181130024918');
('20190720042127'),
('20190720124758');