From 0c758fc40d444da9e1060bb3452e61df405e82df Mon Sep 17 00:00:00 2001 From: Spencer Ferris <3319370+spencewenski@users.noreply.github.com> Date: Sun, 4 Aug 2024 01:01:08 -0700 Subject: [PATCH] feat: Change user.last_sign_in_at column to non-null with default (#312) --- .../m20240723_070533_add_user_account_management_fields.rs | 4 +++- src/migration/user/mod.rs | 4 ++-- ...unt_management_fields__tests__alter_table_add_columns.snap | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/migration/user/m20240723_070533_add_user_account_management_fields.rs b/src/migration/user/m20240723_070533_add_user_account_management_fields.rs index cd4e6593..97bf7306 100644 --- a/src/migration/user/m20240723_070533_add_user_account_management_fields.rs +++ b/src/migration/user/m20240723_070533_add_user_account_management_fields.rs @@ -35,7 +35,9 @@ fn alter_table_add_columns() -> TableAlterStatement { .add_column_if_not_exists(timestamp_with_time_zone_null(User::EmailConfirmationSentAt)) .add_column_if_not_exists(string_null(User::EmailConfirmationToken)) .add_column_if_not_exists(timestamp_with_time_zone_null(User::EmailConfirmedAt)) - .add_column_if_not_exists(timestamp_with_time_zone_null(User::LastSignInAt)) + .add_column_if_not_exists( + timestamp_with_time_zone(User::LastSignInAt).default(Expr::current_timestamp()), + ) .add_column_if_not_exists(timestamp_with_time_zone_null(User::RecoverySentAt)) .add_column_if_not_exists(string_null(User::RecoveryToken)) .add_column_if_not_exists(timestamp_with_time_zone_null(User::EmailChangeSentAt)) diff --git a/src/migration/user/mod.rs b/src/migration/user/mod.rs index 7f64bddb..a98dd3ee 100644 --- a/src/migration/user/mod.rs +++ b/src/migration/user/mod.rs @@ -7,8 +7,8 @@ pub mod m20240714_203551_create_user_table_uuid_pk; pub mod m20240723_070533_add_user_account_management_fields; pub mod m20240724_005115_user_update_timestamp; pub mod m20240729_000812_password_updated_at; -mod m20240729_002549_password_updated_at_function; -mod m20240729_002615_password_updated_at_trigger; +pub mod m20240729_002549_password_updated_at_function; +pub mod m20240729_002615_password_updated_at_trigger; #[cfg(test)] mod tests; diff --git a/src/migration/user/snapshots/roadster__migration__user__m20240723_070533_add_user_account_management_fields__tests__alter_table_add_columns.snap b/src/migration/user/snapshots/roadster__migration__user__m20240723_070533_add_user_account_management_fields__tests__alter_table_add_columns.snap index d881cfd9..cf8ee86a 100644 --- a/src/migration/user/snapshots/roadster__migration__user__m20240723_070533_add_user_account_management_fields__tests__alter_table_add_columns.snap +++ b/src/migration/user/snapshots/roadster__migration__user__m20240723_070533_add_user_account_management_fields__tests__alter_table_add_columns.snap @@ -2,4 +2,4 @@ source: src/migration/user/m20240723_070533_add_user_account_management_fields.rs expression: query.to_string(PostgresQueryBuilder) --- -ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "email_confirmation_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "email_confirmation_token" varchar NULL, ADD COLUMN IF NOT EXISTS "email_confirmed_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "last_sign_in_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "recovery_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "recovery_token" varchar NULL, ADD COLUMN IF NOT EXISTS "email_change_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "email_change_token_new" varchar NULL, ADD COLUMN IF NOT EXISTS "email_change_token_current" varchar NULL, ADD COLUMN IF NOT EXISTS "deleted_at" timestamp with time zone NULL +ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "email_confirmation_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "email_confirmation_token" varchar NULL, ADD COLUMN IF NOT EXISTS "email_confirmed_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "last_sign_in_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD COLUMN IF NOT EXISTS "recovery_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "recovery_token" varchar NULL, ADD COLUMN IF NOT EXISTS "email_change_sent_at" timestamp with time zone NULL, ADD COLUMN IF NOT EXISTS "email_change_token_new" varchar NULL, ADD COLUMN IF NOT EXISTS "email_change_token_current" varchar NULL, ADD COLUMN IF NOT EXISTS "deleted_at" timestamp with time zone NULL