From acb79a2cf21444bc2e786774c3c85c30f2548218 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Tue, 23 Feb 2021 04:49:21 +0700 Subject: [PATCH] Add check constraint for users.username (#12741) --- ...210219043102_add_check_constraint_for_username.rb | 12 ++++++++++++ db/schema.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210219043102_add_check_constraint_for_username.rb diff --git a/db/migrate/20210219043102_add_check_constraint_for_username.rb b/db/migrate/20210219043102_add_check_constraint_for_username.rb new file mode 100644 index 000000000..8d45260b0 --- /dev/null +++ b/db/migrate/20210219043102_add_check_constraint_for_username.rb @@ -0,0 +1,12 @@ +class AddCheckConstraintForUsername < ActiveRecord::Migration[6.0] + def change + safety_assured do + execute(<<~SQL.squish) + ALTER TABLE "users" + ADD CONSTRAINT "users_username_not_null" + CHECK ("username" IS NOT NULL) + NOT VALID + SQL + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 91a7f04fc..7e003b737 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_02_16_023520) do +ActiveRecord::Schema.define(version: 2021_02_19_043102) do # These are extensions that must be enabled in order to support this database enable_extension "citext"