From 676ae18ca21b95bc2aa522198899b261c54d0ebd Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 28 Jan 2026 20:01:31 -0500 Subject: [PATCH] new users table fields --- .../down.sql | 7 ++++++ .../up.sql | 7 ++++++ .../down.sql | 7 ++++++ .../up.sql | 7 ++++++ .../down.sql | 7 ++++++ .../up.sql | 7 ++++++ .../migrations_squashed/user_tables/users.sql | 25 +++++++++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 _database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/down.sql create mode 100644 _database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/up.sql create mode 100644 _database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/down.sql create mode 100644 _database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/up.sql create mode 100644 _database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/down.sql create mode 100644 _database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/up.sql diff --git a/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/down.sql b/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/down.sql new file mode 100644 index 0000000000..72a7d3a662 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/down.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +DROP COLUMN +was_eagerly_provisioned; diff --git a/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/up.sql b/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/up.sql new file mode 100644 index 0000000000..2e1015b685 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232018_alter_users_add_was_eagerly_provisioned/up.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +ADD COLUMN +was_eagerly_provisioned BOOLEAN NOT NULL DEFAULT false; diff --git a/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/down.sql b/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/down.sql new file mode 100644 index 0000000000..805d6441e4 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/down.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +DROP COLUMN +is_temporary; diff --git a/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/up.sql b/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/up.sql new file mode 100644 index 0000000000..4e37896922 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232025_alter_users_add_is_temporary/up.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +ADD COLUMN +is_temporary BOOLEAN NOT NULL DEFAULT false; diff --git a/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/down.sql b/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/down.sql new file mode 100644 index 0000000000..7a012a5073 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/down.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +DROP COLUMN +email_is_synthetic; diff --git a/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/up.sql b/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/up.sql new file mode 100644 index 0000000000..a99ef71e13 --- /dev/null +++ b/_database/sql/migrations/2026-01-28-232044_alter_users_add_email_is_synthetic/up.sql @@ -0,0 +1,7 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +ALTER TABLE users +ADD COLUMN +email_is_synthetic BOOLEAN NOT NULL DEFAULT false; diff --git a/_database/sql/migrations_squashed/user_tables/users.sql b/_database/sql/migrations_squashed/user_tables/users.sql index 76c570bf39..fc78d486d5 100644 --- a/_database/sql/migrations_squashed/user_tables/users.sql +++ b/_database/sql/migrations_squashed/user_tables/users.sql @@ -12,6 +12,14 @@ CREATE TABLE users ( -- Visible "primary key" token VARCHAR(32) NOT NULL, + -- This is TRUE for accounts that were provisioned automatically (eg. eager stripe + -- checkout flow), and who haven't completed onboarding (eg. finishing with billing). + -- Once the user finishes setup, this is set to FALSE. + -- Existing users and normal signup flow always sets this to FALSE. + -- If enough time has elapsed for an incomplete `is_temporary` user, such user records + -- might be possible to delete as we assume the user abandoned sign up long ago. + is_temporary BOOLEAN NOT NULL DEFAULT false, + -- Username is a lookup key; display_name allows the user to add custom case. username VARCHAR(20) NOT NULL, display_name VARCHAR(20) NOT NULL, @@ -30,6 +38,8 @@ CREATE TABLE users ( -- Set by the user at sign up: -- - When email + password signup, this is the email provided. -- - When Google SSO, this is the email provided by Google. + -- - When "eager" checkout flow, this is synthetically generated and + -- updated by the user later. email_address VARCHAR(255) NOT NULL, -- Email address is confirmed by us. @@ -39,6 +49,11 @@ CREATE TABLE users ( -- Email address is confirmed by Google. email_confirmed_by_google BOOLEAN NOT NULL DEFAULT false, + -- We created a user account provisionally, and the email address is not yet real. + -- This happens during "eager" checkout flow before users create accounts - we create + -- a user account for them with a fake email address (since this is a unique key). + email_is_synthetic BOOLEAN NOT NULL DEFAULT false, + -- The role assigned to the user confers permissions. user_role_slug VARCHAR(16) NOT NULL, @@ -86,6 +101,7 @@ CREATE TABLE users ( password_version INT UNSIGNED NOT NULL DEFAULT 0, -- Users signing up from SSO do not have a password at time of account creation. + -- Users signing up with eager stripe checkout flow do not have a password at time of creation is_without_password BOOLEAN NOT NULL DEFAULT false, -- ========== ABUSE TRACKING ========== @@ -193,8 +209,17 @@ CREATE TABLE users ( -- How users created their account -- Initially this will be "email_password" or "google_sign_in" -- Older users do not have a value and are assumed to be "email_sign_in" + -- Values: + -- - "email_sign_in" / "email_password" (todo: check which is correct) + -- - "google_sign_in" + -- - "stripe_checkout" (eager stripe checkout account provisioning) maybe_signup_method VARCHAR(16) DEFAULT NULL, + -- Account was provisioned automatically (eg. stripe eager checkout flow) + -- This will remain true even if the user finishes account setup, email change, + -- password setup, etc. + was_eagerly_provisioned BOOLEAN NOT NULL DEFAULT false, + -- ========== MODERATION DETAILS ========== -- Different than deleted.