diff --git a/crates/db/migrations/20260402030000_strict_employee_separation.up.sql b/crates/db/migrations/20260402030000_strict_employee_separation.up.sql index 44da563..82db9d4 100644 --- a/crates/db/migrations/20260402030000_strict_employee_separation.up.sql +++ b/crates/db/migrations/20260402030000_strict_employee_separation.up.sql @@ -1,10 +1,16 @@ -- UP: 20260402030000_strict_employee_separation.up.sql - --- Drop old employees table (was linked to users — replacing with standalone auth) -DROP TABLE IF EXISTS employees CASCADE; +-- +-- Originally: "Drop old employees table (was linked to users - replacing with +-- standalone auth)" - a one-time schema transformation. The db-migrate tool +-- (crates/db-migrate) has no applied-migrations tracking table; it replays +-- every .sql file on every run, which turned this one-time DROP TABLE ... +-- CASCADE into a destructive operation that wiped the live employees table +-- (and every employee account, including admin accounts) on every migration +-- run. The standalone-schema transition already happened in production long +-- ago, so this is now safely a plain idempotent create. -- 1. EMPLOYEES (Standalone Table - Not Linked to 'users') -CREATE TABLE employees ( +CREATE TABLE IF NOT EXISTS employees ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, diff --git a/crates/db/migrations/20260719000926_employees_phone_column.down.sql b/crates/db/migrations/20260719000926_employees_phone_column.down.sql new file mode 100644 index 0000000..eb01aee --- /dev/null +++ b/crates/db/migrations/20260719000926_employees_phone_column.down.sql @@ -0,0 +1 @@ +ALTER TABLE employees DROP COLUMN IF EXISTS phone; diff --git a/crates/db/migrations/20260719000926_employees_phone_column.up.sql b/crates/db/migrations/20260719000926_employees_phone_column.up.sql new file mode 100644 index 0000000..dce1d31 --- /dev/null +++ b/crates/db/migrations/20260719000926_employees_phone_column.up.sql @@ -0,0 +1,7 @@ +-- The employees table has always had a `phone` column in production (queried +-- by EmployeeRepository::get_by_email/get_by_id/list) but no migration ever +-- created it - it was added out-of-band at some point outside the tracked +-- migration files, and was lost when 20260402030000_strict_employee_separation +-- dropped and recreated the table. Restore it as a tracked column going forward. + +ALTER TABLE employees ADD COLUMN IF NOT EXISTS phone VARCHAR(20);