From 0535079c1cf7399c4076364a686b4d8b5f3495d6 Mon Sep 17 00:00:00 2001 From: Sundog Date: Fri, 1 Dec 2023 10:57:46 -0500 Subject: [PATCH] Updates schema, adds PersonShippingAddresses table --- DEVELOP.md | 2 +- migrations/20231101134457_initial-schema.sql | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/DEVELOP.md b/DEVELOP.md index bee63cc..11f4f2a 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -8,4 +8,4 @@ You will need to initialize a sqlite database store: `touch aural_isle.sqlite.db You will need to copy the example env file to .env: `cp env.example .env` -Then you should be able to run the initial database migrations: `sqlx migrate run` \ No newline at end of file +Then you should be able to run the initial database migrations: `sqlx migrate run`. (During initial dev, if you have already ran the initial migration, you will need to delete the sqlite database store and re-create it as above) \ No newline at end of file diff --git a/migrations/20231101134457_initial-schema.sql b/migrations/20231101134457_initial-schema.sql index af5f94b..0abe7c8 100644 --- a/migrations/20231101134457_initial-schema.sql +++ b/migrations/20231101134457_initial-schema.sql @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS Persons ( deleted_at INTEGER, /* timestamp */ deleted_by TEXT(36), /* UUIDv4 */ last_seen INTEGER, /* timestamp */ - shipping_address TEXT, /* optional, should use \n between lines to keep localized format as needed */ + /*shipping_address TEXT,*/ /* optional, should use \n between lines to keep localized format as needed - UPDATE: moving to lookup table */ CONSTRAINT Persons_PK PRIMARY KEY (id), CONSTRAINT Persons_FK FOREIGN KEY (modified_by) REFERENCES Persons(id), CONSTRAINT Persons_FK_1 FOREIGN KEY (deleted_by) REFERENCES Persons(id) @@ -31,6 +31,24 @@ CREATE INDEX IF NOT EXISTS Persons_is_active_IDX ON Persons (is_active); CREATE INDEX IF NOT EXISTS Persons_is_blocked_IDX ON Persons (is_blocked); CREATE INDEX IF NOT EXISTS Persons_deleted_at_IDX ON Persons (deleted_at); +-- The PersonShippingAddresses table is a one-to-many lookup table relating a Person to zero or more shipping addresses +CREATE TABLE IF NOT EXISTS PersonShippingAddresses ( + id TEXT(36), /* UUIDv4 */ + person_id TEXT(36), /* UUIDv4 */ + shipping_address TEXT, /* mandatory, should use \n between lines to keep localized format as needed */ + is_primary INTEGER DEFAULT (0), /* bool, default false */ + created_at INTEGER, /* timestamp */ + modified_at INTEGER, /* timestamp */ + modified_by TEXT(36), /* UUIDv4 */ + deleted_at INTEGER, /* timestamp */ + deleted_by TEXT(36), /* UUIDv4 */ + CONSTRAINT PersonShippingAddresses_PK PRIMARY KEY (id), + CONSTRAINT PersonShippingAddresses_FK FOREIGN KEY (person_id) REFERENCES Persons(id), + CONSTRAINT PersonShippingAddresses_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id), + CONSTRAINT PersonShippingAddresses_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id) +); +CREATE UNIQUE INDEX IF NOT EXISTS PersonShippingAddresses_is_primary_IDX ON PersonShippingAddresses (is_primary); + -- The PersonEmails table is a one-to-many lookup table relating a Person to zero or more email addresses CREATE TABLE IF NOT EXISTS PersonEmails ( person_id TEXT(36),