Commit 61bfd65f authored by Zhu Shung's avatar Zhu Shung Committed by Andreas Brandl

Add phone to user_details and create verification_codes

parent f21f76b8
# frozen_string_literal: true
class AddPhoneToUserDetails < Gitlab::Database::Migration[1.0]
enable_lock_retries!
# rubocop:disable Migration/AddLimitToTextColumns
def up
add_column :user_details, :phone, :text, comment: 'JiHu-specific column'
end
# rubocop:enable Migration/AddLimitToTextColumns
def down
remove_column :user_details, :phone
end
end
# frozen_string_literal: true
class AddTextLimitToUserDetailsPhone < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_text_limit :user_details, :phone, 32
end
def down
remove_text_limit :user_details, :phone
end
end
# frozen_string_literal: true
class AddUniqueIndexPhoneOnUserDetails < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_user_details_on_phone'
def up
add_concurrent_index :user_details, :phone, unique: true, where: 'phone IS NOT NULL', name: INDEX_NAME, comment: 'JiHu-specific index'
end
def down
remove_concurrent_index_by_name :user_details, INDEX_NAME
end
end
# frozen_string_literal: true
class CreateVerificationCodes < Gitlab::Database::Migration[1.0]
include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
def up
constraint_visitor_id_code = check_constraint_name('verification_codes', 'visitor_id_code', 'max_length')
constraint_code = check_constraint_name('verification_codes', 'code', 'max_length')
constraint_phone = check_constraint_name('verification_codes', 'phone', 'max_length')
execute(<<~SQL)
CREATE TABLE verification_codes (
created_at timestamp with time zone NOT NULL DEFAULT NOW(),
visitor_id_code text,
code text,
phone text,
PRIMARY KEY (created_at, visitor_id_code, code, phone),
CONSTRAINT #{constraint_visitor_id_code} CHECK ((char_length(visitor_id_code) <= 64)),
CONSTRAINT #{constraint_code} CHECK ((char_length(code) <= 8)),
CONSTRAINT #{constraint_phone} CHECK ((char_length(phone) <= 32))
) PARTITION BY RANGE (created_at);
COMMENT ON TABLE verification_codes IS 'JiHu-specific table';
CREATE UNIQUE INDEX index_verification_codes_on_phone_and_visitor_id_code ON verification_codes (visitor_id_code, phone, created_at);
COMMENT ON INDEX index_verification_codes_on_phone_and_visitor_id_code IS 'JiHu-specific index';
SQL
min_date = Date.today - 1.month
max_date = Date.today + 1.month
create_daterange_partitions('verification_codes', 'created_at', min_date, max_date)
end
def down
drop_table :verification_codes
end
end
c757a7e17433b8ddf15ae6304286fe3da69f820966455e7fbed7282286f5eb67
\ No newline at end of file
b5302b3a2384bd7d0e639f00941efb490c3121a9332f1e73be620ab0f6f3e771
\ No newline at end of file
d3f588e4edded61f36acbf25fba39be17a2ac16f37e9114f2c5c257c47dc1308
\ No newline at end of file
08593002910759482c58f9b31f251d589ab32b540d9614a2c677df11d32f7f26
\ No newline at end of file
......@@ -19851,12 +19851,16 @@ CREATE TABLE user_details (
pronouns text,
pronunciation text,
registration_objective smallint,
phone text,
CONSTRAINT check_245664af82 CHECK ((char_length(webauthn_xid) <= 100)),
CONSTRAINT check_a73b398c60 CHECK ((char_length(phone) <= 32)),
CONSTRAINT check_b132136b01 CHECK ((char_length(other_role) <= 100)),
CONSTRAINT check_eeeaf8d4f0 CHECK ((char_length(pronouns) <= 50)),
CONSTRAINT check_f932ed37db CHECK ((char_length(pronunciation) <= 255))
);
COMMENT ON COLUMN user_details.phone IS 'JiHu-specific column';
CREATE SEQUENCE user_details_user_id_seq
START WITH 1
INCREMENT BY 1
......@@ -20150,6 +20154,19 @@ CREATE SEQUENCE users_statistics_id_seq
ALTER SEQUENCE users_statistics_id_seq OWNED BY users_statistics.id;
CREATE TABLE verification_codes (
created_at timestamp with time zone DEFAULT now() NOT NULL,
visitor_id_code text NOT NULL,
code text NOT NULL,
phone text NOT NULL,
CONSTRAINT check_9b84e6aaff CHECK ((char_length(code) <= 8)),
CONSTRAINT check_ccc542256b CHECK ((char_length(visitor_id_code) <= 64)),
CONSTRAINT check_f5684c195b CHECK ((char_length(phone) <= 32))
)
PARTITION BY RANGE (created_at);
COMMENT ON TABLE verification_codes IS 'JiHu-specific table';
CREATE TABLE vulnerabilities (
id bigint NOT NULL,
milestone_id bigint,
......@@ -23810,6 +23827,9 @@ ALTER TABLE ONLY users_star_projects
ALTER TABLE ONLY users_statistics
ADD CONSTRAINT users_statistics_pkey PRIMARY KEY (id);
ALTER TABLE ONLY verification_codes
ADD CONSTRAINT verification_codes_pkey PRIMARY KEY (created_at, visitor_id_code, code, phone);
ALTER TABLE ONLY vulnerabilities
ADD CONSTRAINT vulnerabilities_pkey PRIMARY KEY (id);
......@@ -26764,6 +26784,10 @@ CREATE INDEX index_user_custom_attributes_on_key_and_value ON user_custom_attrib
CREATE UNIQUE INDEX index_user_custom_attributes_on_user_id_and_key ON user_custom_attributes USING btree (user_id, key);
CREATE UNIQUE INDEX index_user_details_on_phone ON user_details USING btree (phone) WHERE (phone IS NOT NULL);
COMMENT ON INDEX index_user_details_on_phone IS 'JiHu-specific index';
CREATE INDEX index_user_details_on_provisioned_by_group_id ON user_details USING btree (provisioned_by_group_id);
CREATE UNIQUE INDEX index_user_details_on_user_id ON user_details USING btree (user_id);
......@@ -26846,6 +26870,10 @@ CREATE INDEX index_users_star_projects_on_project_id ON users_star_projects USIN
CREATE UNIQUE INDEX index_users_star_projects_on_user_id_and_project_id ON users_star_projects USING btree (user_id, project_id);
CREATE UNIQUE INDEX index_verification_codes_on_phone_and_visitor_id_code ON ONLY verification_codes USING btree (visitor_id_code, phone, created_at);
COMMENT ON INDEX index_verification_codes_on_phone_and_visitor_id_code IS 'JiHu-specific index';
CREATE UNIQUE INDEX index_vuln_historical_statistics_on_project_id_and_date ON vulnerability_historical_statistics USING btree (project_id, date);
CREATE INDEX index_vulnerabilities_on_author_id ON vulnerabilities USING btree (author_id);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment