Method: ApplicationSetting.check_schema!

Defined in:
app/models/application_setting.rb

.check_schema!Object

Due to the frequency with which settings are accessed, it is likely that during a backup restore a running GitLab process will insert a new application_settings row before the constraints have been added to the table. This would add an extra row with ID 1 and prevent the primary key constraint from being added, which made ActiveRecord throw a IrreversibleOrderError anytime the settings were accessed (gitlab.com/gitlab-org/gitlab/-/issues/36405). To prevent this from happening, we do a sanity check that the primary key constraint is present before inserting a new entry.



1198
1199
1200
1201
1202
# File 'app/models/application_setting.rb', line 1198

def self.check_schema!
  return if connection.primary_key(table_name).present?

  raise "The `#{table_name}` table is missing a primary key constraint in the database schema"
end