From 2f41b0dd572648716b82b38cd90820cf3d3f10dc Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 4 Apr 2025 20:27:46 +0200 Subject: [PATCH] Add active_until to users --- ...82629_set_active_until_for_selfhosted_users.rb | 15 +++++++++++++++ db/data_schema.rb | 2 +- .../20250404182437_add_active_until_to_users.rb | 7 +++++++ db/schema.rb | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 db/data/20250404182629_set_active_until_for_selfhosted_users.rb create mode 100644 db/migrate/20250404182437_add_active_until_to_users.rb diff --git a/db/data/20250404182629_set_active_until_for_selfhosted_users.rb b/db/data/20250404182629_set_active_until_for_selfhosted_users.rb new file mode 100644 index 00000000..2d622774 --- /dev/null +++ b/db/data/20250404182629_set_active_until_for_selfhosted_users.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class SetActiveUntilForSelfhostedUsers < ActiveRecord::Migration[8.0] + def up + return unless DawarichSettings.self_hosted? + + # rubocop:disable Rails/SkipsModelValidations + User.where(active_until: nil).update_all(active_until: 1000.years.from_now) + # rubocop:enable Rails/SkipsModelValidations + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/data_schema.rb b/db/data_schema.rb index c8d2c368..c483f963 100644 --- a/db/data_schema.rb +++ b/db/data_schema.rb @@ -1 +1 @@ -DataMigrate::Data.define(version: 20250403204658) +DataMigrate::Data.define(version: 20250404182629) diff --git a/db/migrate/20250404182437_add_active_until_to_users.rb b/db/migrate/20250404182437_add_active_until_to_users.rb new file mode 100644 index 00000000..f42ca9b4 --- /dev/null +++ b/db/migrate/20250404182437_add_active_until_to_users.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddActiveUntilToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :active_until, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index f6e71855..2c9db849 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[8.0].define(version: 2025_03_24_180755) do +ActiveRecord::Schema[8.0].define(version: 2025_04_04_182437) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" enable_extension "postgis" @@ -230,6 +230,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_24_180755) do t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.integer "status", default: 0 + t.datetime "active_until" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end