DAST On-demand Scheduler - Implement Scheduling [RUN ALL RSPEC] [RUN AS-IF-FOSS]
What does this MR do?
Implement Scheduling Logic for DAST On-demand Scheduler
- Add new cron job app_sec_dast_profile_schedule_worker. Currently, the cron job is configured to run every 15th minute of an hour.
- Add ProfileScheduleWorker. This worker will periodically run all the runnable_schedules from Dast::ProfileSchedule.
- Add new table dast_profile_schedules with the following two foreign keys: a. dast_profile_id b. user_id
- Set up one to many relationship between dast_profile and dast_profile_schedule.
- Model dast_profile_schedule will hold the information about the schedules of dast scans.
- Add specs.
- Issue link - #330307 (closed)
Quick steps to test:
- Setup db, Run:
user = User.first # root user
project = user.projects.first # find project with dast enabled
profile = Dast::Profile.find_by(project: project.id)
schedule = Dast::ProfileSchedule.create!(user_id: user.id, cron: "*/10 * * * *", next_run_at: Time.zone.now, dast_profile_id: profile.id, project_id: project.id)
-
Run worker:
AppSec::Dast::ProfileScheduleWorker.new.perform
-
Check the dast job on the dashboard.
Database:
Query plan
Raw SQL
paste.depesz.com
new paste history about contact
Original query:
SELECT "dast_profile_schedules".* FROM "dast_profile_schedules" WHERE "dast_profile_schedules"."active" = TRUE AND (next_run_at < '2021-07-09 09:53:10.288244')
Prettified:
SELECT
"dast_profile_schedules".*
FROM
"dast_profile_schedules"
WHERE
"dast_profile_schedules"."active" = TRUE
AND (next_run_at < '2021-07-09 09:53:10.288244')
Copyright © 2017 Hubert "depesz" Lubaczewski
Powered by mojolicious
Query Plans
Plan:
Index Scan using index_dast_profile_schedules_active_next_run_at on public.dast_profile_schedules (cost=0.15..18.95 rows=115 width=89) (actual time=0.008..0.008 rows=0 loops=1)
Index Cond: ((dast_profile_schedules.active = true) AND (dast_profile_schedules.next_run_at < '2021-07-09 09:53:10.288244+00'::timestamp with time zone))
Buffers: shared hit=2
I/O Timings: read=0.000 write=0.000
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5122/commands/18106
Migration:
╰─>$ rails db:migrate
== 20210713123345 CreateDastProfileSchedule: migrating ========================
-- create_table(:dast_profile_schedules, {:comment=>"{\"owner\":\"group::dynamic analysis\",\"description\":\"Scheduling for scans using DAST Profiles\"}"})
-- quote_column_name(:cron)
-> 0.0000s
-> 0.0170s
-- quote_table_name("check_86531ea73f")
-> 0.0000s
-- quote_table_name(:dast_profile_schedules)
-> 0.0000s
-- execute("ALTER TABLE \"dast_profile_schedules\"\nADD CONSTRAINT \"check_86531ea73f\" CHECK (char_length(\"cron\") <= 255)\n")
-> 0.0010s
== 20210713123345 CreateDastProfileSchedule: migrated (0.0252s) ===============
== 20210715074359 AddForeignKeyToDastProfileSchedulesOnDastProfile: migrating =
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:dast_profile_schedules)
-> 0.0034s
-- execute("ALTER TABLE dast_profile_schedules\nADD CONSTRAINT fk_61d52aa0e7\nFOREIGN KEY (dast_profile_id)\nREFERENCES dast_profiles (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0015s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- execute("ALTER TABLE dast_profile_schedules VALIDATE CONSTRAINT fk_61d52aa0e7;")
-> 0.0029s
-- execute("RESET ALL")
-> 0.0005s
== 20210715074359 AddForeignKeyToDastProfileSchedulesOnDastProfile: migrated (0.0125s)
== 20210715074933 AddForeignKeyToDastProfileSchedulesOnUser: migrating ========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:dast_profile_schedules)
-> 0.0021s
-- execute("ALTER TABLE dast_profile_schedules\nADD CONSTRAINT fk_aef03d62e5\nFOREIGN KEY (user_id)\nREFERENCES users (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0014s
-- execute("ALTER TABLE dast_profile_schedules VALIDATE CONSTRAINT fk_aef03d62e5;")
-> 0.0043s
== 20210715074933 AddForeignKeyToDastProfileSchedulesOnUser: migrated (0.0113s)
== 20210715075203 AddForeignKeyToDastProfileSchedulesOnProject: migrating =====
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:dast_profile_schedules)
-> 0.0022s
-- execute("ALTER TABLE dast_profile_schedules\nADD CONSTRAINT fk_6cca0d8800\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0016s
-- execute("ALTER TABLE dast_profile_schedules VALIDATE CONSTRAINT fk_6cca0d8800;")
-> 0.0062s
== 20210715075203 AddForeignKeyToDastProfileSchedulesOnProject: migrated (0.0136s)
Rollback
╰─>$ rails db:rollback STEP=4
== 20210715075203 AddForeignKeyToDastProfileSchedulesOnProject: reverting =====
-- foreign_keys(:dast_profile_schedules)
-> 0.0038s
-- remove_foreign_key(:dast_profile_schedules, {:column=>:project_id})
-> 0.0036s
== 20210715075203 AddForeignKeyToDastProfileSchedulesOnProject: reverted (0.0131s)
== 20210715074933 AddForeignKeyToDastProfileSchedulesOnUser: reverting ========
-- foreign_keys(:dast_profile_schedules)
-> 0.0018s
-- remove_foreign_key(:dast_profile_schedules, {:column=>:user_id})
-> 0.0028s
== 20210715074933 AddForeignKeyToDastProfileSchedulesOnUser: reverted (0.0075s)
== 20210715074359 AddForeignKeyToDastProfileSchedulesOnDastProfile: reverting =
-- foreign_keys(:dast_profile_schedules)
-> 0.0018s
-- remove_foreign_key(:dast_profile_schedules, {:column=>:dast_profile_id})
-> 0.0026s
== 20210715074359 AddForeignKeyToDastProfileSchedulesOnDastProfile: reverted (0.0075s)
== 20210713123345 CreateDastProfileSchedule: reverting ========================
-- drop_table(:dast_profile_schedules)
-> 0.0025s
== 20210713123345 CreateDastProfileSchedule: reverted (0.0061s) ===============
Dast::ProfileSchedule.with_project.with_profile.with_owner.runnable_schedules.explain
Query Explain for Click to expand
> ::Dast::ProfileSchedule.with_project.with_profile.with_owner.runnable_schedules.explain
Dast::ProfileSchedule Load (0.7ms) SELECT "dast_profile_schedules".* FROM "dast_profile_schedules" WHERE "dast_profile_schedules"."active" = TRUE AND (next_run_at < '2021-07-13 13:30:14.416783') /*application:console,line:(pry):20:in `__pry__'*/
Project Load (0.6ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = 23 /*application:console,line:(pry):20:in `__pry__'*/
Dast::Profile Load (0.3ms) SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."id" = 2 /*application:console,line:(pry):20:in `__pry__'*/
DastSiteProfile Load (0.2ms) SELECT "dast_site_profiles".* FROM "dast_site_profiles" WHERE "dast_site_profiles"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
DastScannerProfile Load (0.3ms) SELECT "dast_scanner_profiles".* FROM "dast_scanner_profiles" WHERE "dast_scanner_profiles"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
=> EXPLAIN for: SELECT "dast_profile_schedules".* FROM "dast_profile_schedules" WHERE "dast_profile_schedules"."active" = TRUE AND (next_run_at < '2021-07-13 13:30:14.416783') /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Index Scan using index_dast_profile_schedules_active_next_run_at on dast_profile_schedules (cost=0.15..13.45 rows=115 width=89)
Index Cond: ((active = true) AND (next_run_at < '2021-07-13 13:30:14.416783+00'::timestamp with time zone))
(2 rows)
EXPLAIN for: SELECT "projects".* FROM "projects" WHERE "projects"."id" = 23 /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_projects_on_repository_storage_last_repository_updated_at on projects (cost=0.14..2.16 rows=1 width=1472)
Index Cond: (id = 23)
(2 rows)
EXPLAIN for: SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."id" = 2 /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
------------------------------------------------------------------------------------------
Index Scan using dast_profiles_pkey on dast_profiles (cost=0.15..2.17 rows=1 width=144)
Index Cond: (id = 2)
(2 rows)
EXPLAIN for: SELECT "dast_site_profiles".* FROM "dast_site_profiles" WHERE "dast_site_profiles"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
----------------------------------------------------------------------------------------------------
Index Scan using dast_site_profiles_pkey on dast_site_profiles (cost=0.15..2.17 rows=1 width=235)
Index Cond: (id = 1)
(2 rows)
EXPLAIN for: SELECT "dast_scanner_profiles".* FROM "dast_scanner_profiles" WHERE "dast_scanner_profiles"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
---------------------------------------------------------------------------------------------------------
Index Scan using dast_scanner_profiles_pkey on dast_scanner_profiles (cost=0.15..2.17 rows=1 width=68)
Index Cond: (id = 1)
(2 rows)
EXPLAIN for: SELECT "users".* FROM "users" WHERE "users"."id" = 1 /*application:console,line:(pry):20:in `__pry__'*/
QUERY PLAN
---------------------------------------------------------------------------
Index Scan using users_pkey on users (cost=0.14..2.16 rows=1 width=2464)
Index Cond: (id = 1)
(2 rows)
Query Explain:
[1] pry(main)> ::Dast::ProfileSchedule.with_project.with_profile.with_owner.runnable_schedules.explain
Creating scope :runnable_schedules. Overwriting existing method Dast::ProfileSchedule.runnable_schedules.
Dast::ProfileSchedule Load (1.5ms) SELECT "dast_profile_schedules".* FROM "dast_profile_schedules" WHERE "dast_profile_schedules"."active" = TRUE AND (next_run_at < '2021-07-09 09:53:10.288244') /*application:console,line:(pry):1:in `__pry__'*/
=> EXPLAIN for: SELECT "dast_profile_schedules".* FROM "dast_profile_schedules" WHERE "dast_profile_schedules"."active" = TRUE AND (next_run_at < '2021-07-09 09:53:10.288244') /*application:console,line:(pry):1:in `__pry__'*/
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Index Scan using index_dast_profile_schedules_active_next_run_at on dast_profile_schedules (cost=0.15..13.45 rows=115 width=89)
Index Cond: ((active = true) AND (next_run_at < '2021-07-09 09:53:10.288244+00'::timestamp with time zone))
(2 rows)
Table: dast_profile_schedules
Table "public.dast_profile_schedules"
Column | Type | Collation | Nullable | Default
-----------------+--------------------------+-----------+----------+----------------------------------------------------
id | bigint | | not null | nextval('dast_profile_schedules_id_seq'::regclass)
dast_profile_id | bigint | | not null |
user_id | bigint | | not null |
project_id | bigint | | not null |
active | boolean | | | true
next_run_at | timestamp with time zone | | not null |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
cron | text | | not null |
Indexes:
"dast_profile_schedules_pkey" PRIMARY KEY, btree (id)
"index_dast_profile_schedules_active_next_run_at" btree (active, next_run_at)
"index_dast_profile_schedules_on_dast_profile_id" btree (dast_profile_id)
"index_dast_profile_schedules_on_project_id" btree (project_id)
"index_dast_profile_schedules_on_user_id" btree (user_id)
Check constraints:
"check_86531ea73f" CHECK (char_length(cron) <= 255)
Foreign-key constraints:
"fk_61d52aa0e7" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
"fk_6cca0d8800" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_aef03d62e5" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
Table: dast_profiles
before
Table "public.dast_profiles"
Column | Type | Collation | Nullable | Default
-------------------------+--------------------------+-----------+----------+-------------------------------------------
id | bigint | | not null | nextval('dast_profiles_id_seq'::regclass)
project_id | bigint | | not null |
dast_site_profile_id | bigint | | not null |
dast_scanner_profile_id | bigint | | not null |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
name | text | | not null |
description | text | | not null |
branch_name | text | | |
Indexes:
"dast_profiles_pkey" PRIMARY KEY, btree (id)
"index_dast_profiles_on_project_id_and_name" UNIQUE, btree (project_id, name)
"index_dast_profiles_on_dast_scanner_profile_id" btree (dast_scanner_profile_id)
"index_dast_profiles_on_dast_site_profile_id" btree (dast_site_profile_id)
Check constraints:
"check_5fcf73bf61" CHECK (char_length(name) <= 255)
"check_6c9d775949" CHECK (char_length(branch_name) <= 255)
"check_c34e505c24" CHECK (char_length(description) <= 255)
Foreign-key constraints:
"fk_aa76ef30e9" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_rails_23cae5abe1" FOREIGN KEY (dast_scanner_profile_id) REFERENCES dast_scanner_profiles(id) ON DELETE CASCADE
"fk_rails_ed1e66fbbf" FOREIGN KEY (dast_site_profile_id) REFERENCES dast_site_profiles(id) ON DELETE CASCADE
Referenced by:
TABLE "dast_profiles_pipelines" CONSTRAINT "fk_cc206a8c13" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
after
Table "public.dast_profiles"
Column | Type | Collation | Nullable | Default
-------------------------+--------------------------+-----------+----------+-------------------------------------------
id | bigint | | not null | nextval('dast_profiles_id_seq'::regclass)
project_id | bigint | | not null |
dast_site_profile_id | bigint | | not null |
dast_scanner_profile_id | bigint | | not null |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
name | text | | not null |
description | text | | not null |
branch_name | text | | |
Indexes:
"dast_profiles_pkey" PRIMARY KEY, btree (id)
"index_dast_profiles_on_project_id_and_name" UNIQUE, btree (project_id, name)
"index_dast_profiles_on_dast_scanner_profile_id" btree (dast_scanner_profile_id)
"index_dast_profiles_on_dast_site_profile_id" btree (dast_site_profile_id)
Check constraints:
"check_5fcf73bf61" CHECK (char_length(name) <= 255)
"check_6c9d775949" CHECK (char_length(branch_name) <= 255)
"check_c34e505c24" CHECK (char_length(description) <= 255)
Foreign-key constraints:
"fk_aa76ef30e9" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_rails_23cae5abe1" FOREIGN KEY (dast_scanner_profile_id) REFERENCES dast_scanner_profiles(id) ON DELETE CASCADE
"fk_rails_ed1e66fbbf" FOREIGN KEY (dast_site_profile_id) REFERENCES dast_site_profiles(id) ON DELETE CASCADE
Referenced by:
TABLE "dast_profile_schedules" CONSTRAINT "fk_61d52aa0e7" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
TABLE "dast_profiles_pipelines" CONSTRAINT "fk_cc206a8c13" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
Diff
TABLE "dast_profile_schedules" CONSTRAINT "fk_61d52aa0e7" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
Table: users
before
Table "public.dast_profiles"
Column | Type | Collation | Nullable | Default
-------------------------+--------------------------+-----------+----------+-------------------------------------------
id | bigint | | not null | nextval('dast_profiles_id_seq'::regclass)
project_id | bigint | | not null |
dast_site_profile_id | bigint | | not null |
dast_scanner_profile_id | bigint | | not null |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
name | text | | not null |
description | text | | not null |
branch_name | text | | |
Indexes:
"dast_profiles_pkey" PRIMARY KEY, btree (id)
"index_dast_profiles_on_project_id_and_name" UNIQUE, btree (project_id, name)
"index_dast_profiles_on_dast_scanner_profile_id" btree (dast_scanner_profile_id)
"index_dast_profiles_on_dast_site_profile_id" btree (dast_site_profile_id)
Check constraints:
"check_5fcf73bf61" CHECK (char_length(name) <= 255)
"check_6c9d775949" CHECK (char_length(branch_name) <= 255)
"check_c34e505c24" CHECK (char_length(description) <= 255)
Foreign-key constraints:
"fk_aa76ef30e9" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_rails_23cae5abe1" FOREIGN KEY (dast_scanner_profile_id) REFERENCES dast_scanner_profiles(id) ON DELETE CASCADE
"fk_rails_ed1e66fbbf" FOREIGN KEY (dast_site_profile_id) REFERENCES dast_site_profiles(id) ON DELETE CASCADE
Referenced by:
TABLE "dast_profiles_pipelines" CONSTRAINT "fk_cc206a8c13" FOREIGN KEY (dast_profile_id) REFERENCES dast_profiles(id) ON DELETE CASCADE
gitlabhq_development=#
gitlabhq_development=# \d users
Table "public.users"
Column | Type | Collation | Nullable | Default
----------------------------------------------+-----------------------------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('users_id_seq'::regclass)
email | character varying | | not null | ''::character varying
encrypted_password | character varying | | not null | ''::character varying
reset_password_token | character varying | | |
reset_password_sent_at | timestamp without time zone | | |
remember_created_at | timestamp without time zone | | |
sign_in_count | integer | | | 0
current_sign_in_at | timestamp without time zone | | |
last_sign_in_at | timestamp without time zone | | |
current_sign_in_ip | character varying | | |
last_sign_in_ip | character varying | | |
created_at | timestamp without time zone | | |
updated_at | timestamp without time zone | | |
name | character varying | | |
admin | boolean | | not null | false
projects_limit | integer | | not null |
skype | character varying | | not null | ''::character varying
linkedin | character varying | | not null | ''::character varying
twitter | character varying | | not null | ''::character varying
failed_attempts | integer | | | 0
locked_at | timestamp without time zone | | |
username | character varying | | |
can_create_group | boolean | | not null | true
can_create_team | boolean | | not null | true
state | character varying | | |
color_scheme_id | integer | | not null | 1
password_expires_at | timestamp without time zone | | |
created_by_id | integer | | |
last_credential_check_at | timestamp without time zone | | |
avatar | character varying | | |
confirmation_token | character varying | | |
confirmed_at | timestamp without time zone | | |
confirmation_sent_at | timestamp without time zone | | |
unconfirmed_email | character varying | | |
hide_no_ssh_key | boolean | | | false
website_url | character varying | | not null | ''::character varying
admin_email_unsubscribed_at | timestamp without time zone | | |
notification_email | character varying | | |
hide_no_password | boolean | | | false
password_automatically_set | boolean | | | false
location | character varying | | |
encrypted_otp_secret | character varying | | |
encrypted_otp_secret_iv | character varying | | |
encrypted_otp_secret_salt | character varying | | |
otp_required_for_login | boolean | | not null | false
otp_backup_codes | text | | |
public_email | character varying | | not null | ''::character varying
dashboard | integer | | | 0
project_view | integer | | | 0
consumed_timestep | integer | | |
layout | integer | | | 0
hide_project_limit | boolean | | | false
note | text | | |
unlock_token | character varying | | |
otp_grace_period_started_at | timestamp without time zone | | |
external | boolean | | | false
incoming_email_token | character varying | | |
organization | character varying | | |
auditor | boolean | | not null | false
require_two_factor_authentication_from_group | boolean | | not null | false
two_factor_grace_period | integer | | not null | 48
last_activity_on | date | | |
notified_of_own_activity | boolean | | |
preferred_language | character varying | | |
email_opted_in | boolean | | |
email_opted_in_ip | character varying | | |
email_opted_in_source_id | integer | | |
email_opted_in_at | timestamp without time zone | | |
theme_id | smallint | | |
accepted_term_id | integer | | |
feed_token | character varying | | |
private_profile | boolean | | not null | false
roadmap_layout | smallint | | |
include_private_contributions | boolean | | |
commit_email | character varying | | |
group_view | integer | | |
managing_group_id | integer | | |
first_name | character varying(255) | | |
last_name | character varying(255) | | |
static_object_token | character varying(255) | | |
role | smallint | | |
user_type | smallint | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"index_users_on_confirmation_token" UNIQUE, btree (confirmation_token)
"index_users_on_email" UNIQUE, btree (email)
"index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)
"index_users_on_static_object_token" UNIQUE, btree (static_object_token)
"index_users_on_unlock_token" UNIQUE, btree (unlock_token)
"active_billable_users" btree (id) WHERE state::text = 'active'::text AND (user_type IS NULL OR (user_type = ANY (ARRAY[NULL::integer, 6, 4]))) AND (user_type IS NULL OR (user_type <> ALL ('{2,6,1,3,7,8}'::sm
allint[])))
"index_on_users_lower_email" btree (lower(email::text))
"index_on_users_lower_username" btree (lower(username::text))
"index_on_users_name_lower" btree (lower(name::text))
"index_users_on_accepted_term_id" btree (accepted_term_id)
"index_users_on_admin" btree (admin)
"index_users_on_created_at" btree (created_at)
"index_users_on_email_trigram" gin (email gin_trgm_ops)
"index_users_on_feed_token" btree (feed_token)
"index_users_on_group_view" btree (group_view)
"index_users_on_id_and_last_activity_on_for_non_internal_active" btree (id, last_activity_on) WHERE state::text = 'active'::text AND (user_type IS NULL OR (user_type = ANY (ARRAY[NULL::integer, 6, 4])))
"index_users_on_incoming_email_token" btree (incoming_email_token)
"index_users_on_managing_group_id" btree (managing_group_id)
"index_users_on_name" btree (name)
"index_users_on_name_trigram" gin (name gin_trgm_ops)
"index_users_on_public_email" btree (public_email) WHERE public_email::text <> ''::text
"index_users_on_require_two_factor_authentication_from_group" btree (require_two_factor_authentication_from_group) WHERE require_two_factor_authentication_from_group = true
"index_users_on_state" btree (state)
"index_users_on_state_and_user_type" btree (state, user_type)
"index_users_on_unconfirmed_email" btree (unconfirmed_email) WHERE unconfirmed_email IS NOT NULL
"index_users_on_user_type" btree (user_type)
"index_users_on_username" btree (username)
"index_users_on_username_trigram" gin (username gin_trgm_ops)
"index_users_require_two_factor_authentication_from_group_false" btree (require_two_factor_authentication_from_group) WHERE require_two_factor_authentication_from_group = false
Foreign-key constraints:
"fk_789cd90b35" FOREIGN KEY (accepted_term_id) REFERENCES application_setting_terms(id) ON DELETE CASCADE
"fk_a4b8fefe3e" FOREIGN KEY (managing_group_id) REFERENCES namespaces(id) ON DELETE SET NULL
Referenced by:
TABLE "issues" CONSTRAINT "fk_05f1e72feb" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "user_interacted_projects" CONSTRAINT "fk_0894651f08" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "notification_settings" CONSTRAINT "fk_0c95e91db7" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "group_deletion_schedules" CONSTRAINT "fk_11e3ebfcdd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerabilities" CONSTRAINT "fk_1302949740" FOREIGN KEY (last_edited_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "projects" CONSTRAINT "fk_25d8780d11" FOREIGN KEY (marked_for_deletion_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "members" CONSTRAINT "fk_2e88fb7ce9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "in_product_marketing_emails" CONSTRAINT "fk_35c9101b63" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "epics" CONSTRAINT "fk_3654b61b03" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "terraform_states" CONSTRAINT "fk_558901b030" FOREIGN KEY (locked_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issue_assignees" CONSTRAINT "fk_5e0c8d9154" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "csv_issue_imports" CONSTRAINT "fk_5e1572387c" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "merge_requests" CONSTRAINT "fk_6149611a04" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_requests" CONSTRAINT "fk_641731faff" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "terraform_state_versions" CONSTRAINT "fk_6e81384d7f" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_725465b774" FOREIGN KEY (dismissed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "cluster_agent_tokens" CONSTRAINT "fk_75008f3553" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_76bc5f5455" FOREIGN KEY (resolved_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_7ac31eacb9" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_metrics" CONSTRAINT "fk_7f28d925f3" FOREIGN KEY (merged_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "group_import_states" CONSTRAINT "fk_8053b3ebd6" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "releases" CONSTRAINT "fk_8e4456f90f" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerability_feedback" CONSTRAINT "fk_94f7c8a81e" FOREIGN KEY (comment_author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_959d40ad0a" FOREIGN KEY (confirmed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "application_settings" CONSTRAINT "fk_964370041d" FOREIGN KEY (usage_stats_set_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "ci_pipeline_schedules" CONSTRAINT "fk_9ea99f58d2" FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "epics" CONSTRAINT "fk_aa5798e761" FOREIGN KEY (closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_requests" CONSTRAINT "fk_ad525e1f87" FOREIGN KEY (merge_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_metrics" CONSTRAINT "fk_ae440388cc" FOREIGN KEY (latest_closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_b1de915a15" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "metrics_users_starred_dashboards" CONSTRAINT "fk_bd6ae32fac" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "design_management_versions" CONSTRAINT "fk_c1440b4896" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "packages_packages" CONSTRAINT "fk_c188f0dba4" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issues" CONSTRAINT "fk_c63cbf6c25" FOREIGN KEY (closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "todos" CONSTRAINT "fk_ccf0373936" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "custom_emoji" CONSTRAINT "fk_custom_emoji_creator_id" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "lists" CONSTRAINT "fk_d6cf4279f7" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "todos" CONSTRAINT "fk_d94154aa95" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "epics" CONSTRAINT "fk_dccd3f98fc" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "experiment_subjects" CONSTRAINT "fk_dfc3e211d4" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "merge_requests" CONSTRAINT "fk_e719a85f8a" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "ci_triggers" CONSTRAINT "fk_e8e10d1964" FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "events" CONSTRAINT "fk_edfd187b6f" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "emails" CONSTRAINT "fk_emails_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "boards_epic_list_user_preferences" CONSTRAINT "fk_f5f2fe5c1f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "cluster_agents" CONSTRAINT "fk_f7d43dee13" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issues" CONSTRAINT "fk_ffed080f01" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "path_locks" CONSTRAINT "fk_path_locks_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "personal_access_tokens" CONSTRAINT "fk_personal_access_tokens_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_merge_access_levels" CONSTRAINT "fk_protected_branch_merge_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_push_access_levels" CONSTRAINT "fk_protected_branch_push_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_tag_create_access_levels" CONSTRAINT "fk_protected_tag_create_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_synced_attributes_metadata" CONSTRAINT "fk_rails_0f4aa0981f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_exports" CONSTRAINT "fk_rails_1019162882" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "project_authorizations" CONSTRAINT "fk_rails_11e7aa3ed9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_details" CONSTRAINT "fk_rails_12e0b3043d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "bulk_imports" CONSTRAINT "fk_rails_130a09357d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_assignees" CONSTRAINT "fk_rails_1c0ff59e82" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_statuses" CONSTRAINT "fk_rails_2178592333" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "users_ops_dashboard_projects" CONSTRAINT "fk_rails_220a0562db" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "lfs_file_locks" CONSTRAINT "fk_rails_27a1d98fa8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_credit_card_validations" CONSTRAINT "fk_rails_27ebc03cbf" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "reviews" CONSTRAINT "fk_rails_29e6f859c4" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "draft_notes" CONSTRAINT "fk_rails_2a8dac9901" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_unprotect_access_levels" CONSTRAINT "fk_rails_2d2aba21ef" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "requirements" CONSTRAINT "fk_rails_33fed8aa4e" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_reviewers" CONSTRAINT "fk_rails_3704a66140" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "smartcard_identities" CONSTRAINT "fk_rails_4689f889a9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_feedback" CONSTRAINT "fk_rails_472f69b043" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_custom_attributes" CONSTRAINT "fk_rails_47b91868a8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "aws_roles" CONSTRAINT "fk_rails_4ed56f4720" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_iteration_events" CONSTRAINT "fk_rails_501fa15d69" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "group_deploy_keys" CONSTRAINT "fk_rails_5682fc07f8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT
TABLE "merge_request_assignees" CONSTRAINT "fk_rails_579d375628" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_environment_deploy_access_levels" CONSTRAINT "fk_rails_5b9f6970fe" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "incident_management_oncall_participants" CONSTRAINT "fk_rails_5fe86ea341" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_highest_roles" CONSTRAINT "fk_rails_60f6c325a6" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_group_recent_visits" CONSTRAINT "fk_rails_64bfc19bc5" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "term_agreements" CONSTRAINT "fk_rails_6ea6520e4a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "users_security_dashboard_projects" CONSTRAINT "fk_rails_6f6cf8e66e" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "boards_epic_user_preferences" CONSTRAINT "fk_rails_851fe1510a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_user_preferences" CONSTRAINT "fk_rails_8b3b23ce82" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_merge_request_rules_approved_approvers" CONSTRAINT "fk_rails_8dc94cff4d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "list_user_preferences" CONSTRAINT "fk_rails_916d72cafd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "scim_identities" CONSTRAINT "fk_rails_9421a0bffb" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "packages_debian_project_distributions" CONSTRAINT "fk_rails_94b95e1f84" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "boards_epic_board_recent_visits" CONSTRAINT "fk_rails_96c2c18642" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "gpg_keys" CONSTRAINT "fk_rails_9d1f5d8719" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_preferences" CONSTRAINT "fk_rails_a69bfcfd81" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_permission_export_uploads" CONSTRAINT "fk_rails_a7130085e3" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "clusters" CONSTRAINT "fk_rails_ac3a663d79" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "webauthn_registrations" CONSTRAINT "fk_rails_b15c016782" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "authentication_events" CONSTRAINT "fk_rails_b204656a54" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_trains" CONSTRAINT "fk_rails_b29261ce31" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_merge_request_rules_users" CONSTRAINT "fk_rails_bc8972fa55" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_weight_events" CONSTRAINT "fk_rails_bfc406b47c" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "atlassian_identities" CONSTRAINT "fk_rails_c02928bc18" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_canonical_emails" CONSTRAINT "fk_rails_c2bd828b51" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_milestone_events" CONSTRAINT "fk_rails_cedf8cce4d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "requirements_management_test_reports" CONSTRAINT "fk_rails_d1e8b498bf" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "alert_management_alert_assignees" CONSTRAINT "fk_rails_d47570ac62" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "jira_imports" CONSTRAINT "fk_rails_da617096ce" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "user_callouts" CONSTRAINT "fk_rails_ddfdd80f3d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_external_issue_links" CONSTRAINT "fk_rails_e5ba7f7b13" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "packages_debian_group_distributions" CONSTRAINT "fk_rails_ede0bb937f" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "security_orchestration_policy_rule_schedules" CONSTRAINT "fk_rails_efe1d9b133" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_project_rules_users" CONSTRAINT "fk_rails_f365da8250" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_state_events" CONSTRAINT "fk_rails_f5827a7ccd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "board_project_recent_visits" CONSTRAINT "fk_rails_fb6fc419cb" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "serverless_domain_cluster" CONSTRAINT "fk_rails_fbdba67eb1" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "experiment_users" CONSTRAINT "fk_rails_fd805f771a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_label_events" CONSTRAINT "fk_rails_fe91ece594" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "u2f_registrations" CONSTRAINT "fk_u2f_registrations_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_follow_users" CONSTRAINT "user_follow_users_followee_id_fkey" FOREIGN KEY (followee_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_follow_users" CONSTRAINT "user_follow_users_follower_id_fkey" FOREIGN KEY (follower_id) REFERENCES users(id) ON DELETE CASCADE
After
gitlabhq_development=# \d users
Table "public.users"
Column | Type | Collation | Nullable | Default
----------------------------------------------+-----------------------------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('users_id_seq'::regclass)
email | character varying | | not null | ''::character varying
encrypted_password | character varying | | not null | ''::character varying
reset_password_token | character varying | | |
reset_password_sent_at | timestamp without time zone | | |
remember_created_at | timestamp without time zone | | |
sign_in_count | integer | | | 0
current_sign_in_at | timestamp without time zone | | |
last_sign_in_at | timestamp without time zone | | |
current_sign_in_ip | character varying | | |
last_sign_in_ip | character varying | | |
created_at | timestamp without time zone | | |
updated_at | timestamp without time zone | | |
name | character varying | | |
admin | boolean | | not null | false
projects_limit | integer | | not null |
skype | character varying | | not null | ''::character varying
linkedin | character varying | | not null | ''::character varying
twitter | character varying | | not null | ''::character varying
failed_attempts | integer | | | 0
locked_at | timestamp without time zone | | |
username | character varying | | |
can_create_group | boolean | | not null | true
can_create_team | boolean | | not null | true
state | character varying | | |
color_scheme_id | integer | | not null | 1
password_expires_at | timestamp without time zone | | |
created_by_id | integer | | |
last_credential_check_at | timestamp without time zone | | |
avatar | character varying | | |
confirmation_token | character varying | | |
confirmed_at | timestamp without time zone | | |
confirmation_sent_at | timestamp without time zone | | |
unconfirmed_email | character varying | | |
hide_no_ssh_key | boolean | | | false
website_url | character varying | | not null | ''::character varying
admin_email_unsubscribed_at | timestamp without time zone | | |
notification_email | character varying | | |
hide_no_password | boolean | | | false
password_automatically_set | boolean | | | false
location | character varying | | |
encrypted_otp_secret | character varying | | |
encrypted_otp_secret_iv | character varying | | |
encrypted_otp_secret_salt | character varying | | |
otp_required_for_login | boolean | | not null | false
otp_backup_codes | text | | |
public_email | character varying | | not null | ''::character varying
dashboard | integer | | | 0
project_view | integer | | | 0
consumed_timestep | integer | | |
layout | integer | | | 0
hide_project_limit | boolean | | | false
note | text | | |
unlock_token | character varying | | |
otp_grace_period_started_at | timestamp without time zone | | |
external | boolean | | | false
incoming_email_token | character varying | | |
organization | character varying | | |
auditor | boolean | | not null | false
require_two_factor_authentication_from_group | boolean | | not null | false
two_factor_grace_period | integer | | not null | 48
last_activity_on | date | | |
notified_of_own_activity | boolean | | |
preferred_language | character varying | | |
email_opted_in | boolean | | |
email_opted_in_ip | character varying | | |
email_opted_in_source_id | integer | | |
email_opted_in_at | timestamp without time zone | | |
theme_id | smallint | | |
accepted_term_id | integer | | |
feed_token | character varying | | |
private_profile | boolean | | not null | false
roadmap_layout | smallint | | |
include_private_contributions | boolean | | |
commit_email | character varying | | |
group_view | integer | | |
managing_group_id | integer | | |
first_name | character varying(255) | | |
last_name | character varying(255) | | |
static_object_token | character varying(255) | | |
role | smallint | | |
user_type | smallint | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"index_users_on_confirmation_token" UNIQUE, btree (confirmation_token)
"index_users_on_email" UNIQUE, btree (email)
"index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)
"index_users_on_static_object_token" UNIQUE, btree (static_object_token)
"index_users_on_unlock_token" UNIQUE, btree (unlock_token)
"active_billable_users" btree (id) WHERE state::text = 'active'::text AND (user_type IS NULL OR (user_type = ANY (ARRAY[NULL::integer, 6, 4]))) AND (user_type IS NULL OR (user_type <> ALL ('{2,6,1,3,7,8}'::sm
allint[])))
"index_on_users_lower_email" btree (lower(email::text))
"index_on_users_lower_username" btree (lower(username::text))
"index_on_users_name_lower" btree (lower(name::text))
"index_users_on_accepted_term_id" btree (accepted_term_id)
"index_users_on_admin" btree (admin)
"index_users_on_created_at" btree (created_at)
"index_users_on_email_trigram" gin (email gin_trgm_ops)
"index_users_on_feed_token" btree (feed_token)
"index_users_on_group_view" btree (group_view)
"index_users_on_id_and_last_activity_on_for_non_internal_active" btree (id, last_activity_on) WHERE state::text = 'active'::text AND (user_type IS NULL OR (user_type = ANY (ARRAY[NULL::integer, 6, 4])))
"index_users_on_incoming_email_token" btree (incoming_email_token)
"index_users_on_managing_group_id" btree (managing_group_id)
"index_users_on_name" btree (name)
"index_users_on_name_trigram" gin (name gin_trgm_ops)
"index_users_on_public_email" btree (public_email) WHERE public_email::text <> ''::text
"index_users_on_require_two_factor_authentication_from_group" btree (require_two_factor_authentication_from_group) WHERE require_two_factor_authentication_from_group = true
"index_users_on_state" btree (state)
"index_users_on_state_and_user_type" btree (state, user_type)
"index_users_on_unconfirmed_email" btree (unconfirmed_email) WHERE unconfirmed_email IS NOT NULL
"index_users_on_user_type" btree (user_type)
"index_users_on_username" btree (username)
"index_users_on_username_trigram" gin (username gin_trgm_ops)
"index_users_require_two_factor_authentication_from_group_false" btree (require_two_factor_authentication_from_group) WHERE require_two_factor_authentication_from_group = false
Foreign-key constraints:
"fk_789cd90b35" FOREIGN KEY (accepted_term_id) REFERENCES application_setting_terms(id) ON DELETE CASCADE
"fk_a4b8fefe3e" FOREIGN KEY (managing_group_id) REFERENCES namespaces(id) ON DELETE SET NULL
Referenced by:
TABLE "issues" CONSTRAINT "fk_05f1e72feb" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "user_interacted_projects" CONSTRAINT "fk_0894651f08" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "notification_settings" CONSTRAINT "fk_0c95e91db7" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "group_deletion_schedules" CONSTRAINT "fk_11e3ebfcdd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerabilities" CONSTRAINT "fk_1302949740" FOREIGN KEY (last_edited_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "projects" CONSTRAINT "fk_25d8780d11" FOREIGN KEY (marked_for_deletion_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "members" CONSTRAINT "fk_2e88fb7ce9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "in_product_marketing_emails" CONSTRAINT "fk_35c9101b63" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "epics" CONSTRAINT "fk_3654b61b03" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "terraform_states" CONSTRAINT "fk_558901b030" FOREIGN KEY (locked_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issue_assignees" CONSTRAINT "fk_5e0c8d9154" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "csv_issue_imports" CONSTRAINT "fk_5e1572387c" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "merge_requests" CONSTRAINT "fk_6149611a04" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_requests" CONSTRAINT "fk_641731faff" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "terraform_state_versions" CONSTRAINT "fk_6e81384d7f" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_725465b774" FOREIGN KEY (dismissed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "cluster_agent_tokens" CONSTRAINT "fk_75008f3553" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_76bc5f5455" FOREIGN KEY (resolved_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_7ac31eacb9" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_metrics" CONSTRAINT "fk_7f28d925f3" FOREIGN KEY (merged_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "group_import_states" CONSTRAINT "fk_8053b3ebd6" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "releases" CONSTRAINT "fk_8e4456f90f" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerability_feedback" CONSTRAINT "fk_94f7c8a81e" FOREIGN KEY (comment_author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "vulnerabilities" CONSTRAINT "fk_959d40ad0a" FOREIGN KEY (confirmed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "application_settings" CONSTRAINT "fk_964370041d" FOREIGN KEY (usage_stats_set_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "ci_pipeline_schedules" CONSTRAINT "fk_9ea99f58d2" FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "epics" CONSTRAINT "fk_aa5798e761" FOREIGN KEY (closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_requests" CONSTRAINT "fk_ad525e1f87" FOREIGN KEY (merge_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_metrics" CONSTRAINT "fk_ae440388cc" FOREIGN KEY (latest_closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "dast_profile_schedules" CONSTRAINT "fk_aef03d62e5" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerabilities" CONSTRAINT "fk_b1de915a15" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "metrics_users_starred_dashboards" CONSTRAINT "fk_bd6ae32fac" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "design_management_versions" CONSTRAINT "fk_c1440b4896" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "packages_packages" CONSTRAINT "fk_c188f0dba4" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issues" CONSTRAINT "fk_c63cbf6c25" FOREIGN KEY (closed_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "todos" CONSTRAINT "fk_ccf0373936" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "custom_emoji" CONSTRAINT "fk_custom_emoji_creator_id" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "lists" CONSTRAINT "fk_d6cf4279f7" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "todos" CONSTRAINT "fk_d94154aa95" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "epics" CONSTRAINT "fk_dccd3f98fc" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "experiment_subjects" CONSTRAINT "fk_dfc3e211d4" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "merge_requests" CONSTRAINT "fk_e719a85f8a" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "ci_triggers" CONSTRAINT "fk_e8e10d1964" FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "events" CONSTRAINT "fk_edfd187b6f" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "emails" CONSTRAINT "fk_emails_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "boards_epic_list_user_preferences" CONSTRAINT "fk_f5f2fe5c1f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "cluster_agents" CONSTRAINT "fk_f7d43dee13" FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "issues" CONSTRAINT "fk_ffed080f01" FOREIGN KEY (updated_by_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "path_locks" CONSTRAINT "fk_path_locks_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "personal_access_tokens" CONSTRAINT "fk_personal_access_tokens_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_merge_access_levels" CONSTRAINT "fk_protected_branch_merge_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_push_access_levels" CONSTRAINT "fk_protected_branch_push_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_tag_create_access_levels" CONSTRAINT "fk_protected_tag_create_access_levels_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_synced_attributes_metadata" CONSTRAINT "fk_rails_0f4aa0981f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_exports" CONSTRAINT "fk_rails_1019162882" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "project_authorizations" CONSTRAINT "fk_rails_11e7aa3ed9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_details" CONSTRAINT "fk_rails_12e0b3043d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "bulk_imports" CONSTRAINT "fk_rails_130a09357d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_assignees" CONSTRAINT "fk_rails_1c0ff59e82" FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_statuses" CONSTRAINT "fk_rails_2178592333" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "users_ops_dashboard_projects" CONSTRAINT "fk_rails_220a0562db" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "lfs_file_locks" CONSTRAINT "fk_rails_27a1d98fa8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_credit_card_validations" CONSTRAINT "fk_rails_27ebc03cbf" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "reviews" CONSTRAINT "fk_rails_29e6f859c4" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "draft_notes" CONSTRAINT "fk_rails_2a8dac9901" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_branch_unprotect_access_levels" CONSTRAINT "fk_rails_2d2aba21ef" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "requirements" CONSTRAINT "fk_rails_33fed8aa4e" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_request_reviewers" CONSTRAINT "fk_rails_3704a66140" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "smartcard_identities" CONSTRAINT "fk_rails_4689f889a9" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_feedback" CONSTRAINT "fk_rails_472f69b043" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_custom_attributes" CONSTRAINT "fk_rails_47b91868a8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "aws_roles" CONSTRAINT "fk_rails_4ed56f4720" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_iteration_events" CONSTRAINT "fk_rails_501fa15d69" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "group_deploy_keys" CONSTRAINT "fk_rails_5682fc07f8" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT
TABLE "merge_request_assignees" CONSTRAINT "fk_rails_579d375628" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "protected_environment_deploy_access_levels" CONSTRAINT "fk_rails_5b9f6970fe" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "incident_management_oncall_participants" CONSTRAINT "fk_rails_5fe86ea341" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_highest_roles" CONSTRAINT "fk_rails_60f6c325a6" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_group_recent_visits" CONSTRAINT "fk_rails_64bfc19bc5" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "term_agreements" CONSTRAINT "fk_rails_6ea6520e4a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "users_security_dashboard_projects" CONSTRAINT "fk_rails_6f6cf8e66e" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "boards_epic_user_preferences" CONSTRAINT "fk_rails_851fe1510a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "board_user_preferences" CONSTRAINT "fk_rails_8b3b23ce82" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_merge_request_rules_approved_approvers" CONSTRAINT "fk_rails_8dc94cff4d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "list_user_preferences" CONSTRAINT "fk_rails_916d72cafd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "scim_identities" CONSTRAINT "fk_rails_9421a0bffb" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "packages_debian_project_distributions" CONSTRAINT "fk_rails_94b95e1f84" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "boards_epic_board_recent_visits" CONSTRAINT "fk_rails_96c2c18642" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "gpg_keys" CONSTRAINT "fk_rails_9d1f5d8719" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_preferences" CONSTRAINT "fk_rails_a69bfcfd81" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_permission_export_uploads" CONSTRAINT "fk_rails_a7130085e3" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "clusters" CONSTRAINT "fk_rails_ac3a663d79" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "webauthn_registrations" CONSTRAINT "fk_rails_b15c016782" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "authentication_events" CONSTRAINT "fk_rails_b204656a54" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "merge_trains" CONSTRAINT "fk_rails_b29261ce31" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_merge_request_rules_users" CONSTRAINT "fk_rails_bc8972fa55" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_weight_events" CONSTRAINT "fk_rails_bfc406b47c" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "atlassian_identities" CONSTRAINT "fk_rails_c02928bc18" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_canonical_emails" CONSTRAINT "fk_rails_c2bd828b51" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_milestone_events" CONSTRAINT "fk_rails_cedf8cce4d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "requirements_management_test_reports" CONSTRAINT "fk_rails_d1e8b498bf" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "alert_management_alert_assignees" CONSTRAINT "fk_rails_d47570ac62" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "jira_imports" CONSTRAINT "fk_rails_da617096ce" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "user_callouts" CONSTRAINT "fk_rails_ddfdd80f3d" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "vulnerability_external_issue_links" CONSTRAINT "fk_rails_e5ba7f7b13" FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "packages_debian_group_distributions" CONSTRAINT "fk_rails_ede0bb937f" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "security_orchestration_policy_rule_schedules" CONSTRAINT "fk_rails_efe1d9b133" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "approval_project_rules_users" CONSTRAINT "fk_rails_f365da8250" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_state_events" CONSTRAINT "fk_rails_f5827a7ccd" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "board_project_recent_visits" CONSTRAINT "fk_rails_fb6fc419cb" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "serverless_domain_cluster" CONSTRAINT "fk_rails_fbdba67eb1" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "experiment_users" CONSTRAINT "fk_rails_fd805f771a" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "resource_label_events" CONSTRAINT "fk_rails_fe91ece594" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
TABLE "u2f_registrations" CONSTRAINT "fk_u2f_registrations_user_id" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_follow_users" CONSTRAINT "user_follow_users_followee_id_fkey" FOREIGN KEY (followee_id) REFERENCES users(id) ON DELETE CASCADE
TABLE "user_follow_users" CONSTRAINT "user_follow_users_follower_id_fkey" FOREIGN KEY (follower_id) REFERENCES users(id) ON DELETE CASCADE
Diff
TABLE "dast_profile_schedules" CONSTRAINT "fk_aef03d62e5" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #330307 (closed)
Edited by Aditya Tiwari