Skip to content

Commit

Permalink
Add db comments
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Aug 22, 2024
1 parent 4479808 commit e12dbef
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 232 deletions.
8 changes: 4 additions & 4 deletions demos/ecommerce/source_00_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ C##INVENTORY.PRODUCTS
BRAND BIGINT nullable fk C##INVENTORY.BRANDS.ID
CATEGORY VARCHAR nullable | ex: "Phones"
SUBCATEGORY VARCHAR nullable | ex: "Smartphones"
WIDTH FLOAT | typical width of the product, see PRODUCTS for the real one
LENGTH FLOAT | typical length of the product, see PRODUCTS for the real one
HEIGHT FLOAT | typical height of the product, see PRODUCTS for the real one
WEIGHT FLOAT | typical weight of the product, see PRODUCTS for the real one
WIDTH FLOAT | typical width of the product, see PRODUCT_VERSIONS for the real one
LENGTH FLOAT | typical length of the product, see PRODUCT_VERSIONS for the real one
HEIGHT FLOAT | typical height of the product, see PRODUCT_VERSIONS for the real one
WEIGHT FLOAT | typical weight of the product, see PRODUCT_VERSIONS for the real one
REMARKS TEXT nullable | ex: fragile
CREATED_AT TIMESTAMP
UPDATED_AT TIMESTAMP
Expand Down
9 changes: 3 additions & 6 deletions demos/ecommerce/source_01_referential_sqlserver.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ USE Referential;
CREATE SCHEMA [referential];


CREATE TABLE [referential].[Countries]
(
CREATE TABLE [referential].[Countries] (
[CountryId] [bigint] IDENTITY (1,1) PRIMARY KEY,
[Code] [nvarchar](5) NOT NULL,
[Name] [nvarchar](255) NOT NULL,
Expand All @@ -20,8 +19,7 @@ CREATE INDEX [IDX_Countries_Code] ON [referential].[Countries] ([Code]);
CREATE INDEX [IDX_Countries_Name] ON [referential].[Countries] ([Name]);
EXEC sp_addextendedproperty 'MS_Description', 'needs to be referenced for legal reasons', 'SCHEMA', 'referential', 'TABLE', 'Countries';

CREATE TABLE [referential].[States]
(
CREATE TABLE [referential].[States] (
[StateId] [bigint] IDENTITY (1,1) PRIMARY KEY,
[CountryId] [bigint] NOT NULL,
[Code] [nvarchar](5) NOT NULL,
Expand All @@ -35,8 +33,7 @@ CREATE INDEX [IDX_States_Code] ON [referential].[States] ([Code]);
CREATE INDEX [IDX_States_Name] ON [referential].[States] ([Name]);
EXEC sp_addextendedproperty 'MS_Description', 'used for auto-competes', 'SCHEMA', 'referential', 'TABLE', 'States';

CREATE TABLE [referential].[Cities]
(
CREATE TABLE [referential].[Cities] (
[CityId] [bigint] IDENTITY (1,1) PRIMARY KEY,
[StateId] [bigint] NOT NULL,
[Name] [nvarchar](255) NOT NULL,
Expand Down
21 changes: 7 additions & 14 deletions demos/ecommerce/source_02_identity_mariadb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ CREATE DATABASE identity;
USE identity;


CREATE TABLE identity.Users
(
CREATE TABLE identity.Users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
Expand All @@ -21,8 +20,7 @@ CREATE TABLE identity.Users
INDEX idx_deleted_at (deleted_at)
);

CREATE TABLE identity.Credentials
(
CREATE TABLE identity.Credentials (
user_id BIGINT NOT NULL REFERENCES identity.Users (id),
provider ENUM ('password', 'google', 'linkedin', 'facebook', 'twitter') NOT NULL COMMENT 'the used provider',
provider_id VARCHAR(255) NOT NULL COMMENT 'the user id from the provider, in case of password, stores the hashed password with the salt',
Expand All @@ -34,8 +32,7 @@ CREATE TABLE identity.Credentials
PRIMARY KEY (user_id, provider, provider_id)
);

CREATE TABLE identity.PasswordResets
(
CREATE TABLE identity.PasswordResets (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
token VARCHAR(255) NOT NULL COMMENT 'the key sent by email to allow to change the password without being logged',
Expand All @@ -46,25 +43,22 @@ CREATE TABLE identity.PasswordResets
INDEX idx_token (token)
);

CREATE TABLE identity.Devices
(
CREATE TABLE identity.Devices (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
sid CHAR(36) NOT NULL UNIQUE COMMENT 'a unique id stored in the browser to track it when not logged',
user_agent VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'first time this device is seen'
) COMMENT 'a device is a browser tagged by a random id in its session';

CREATE TABLE identity.UserDevices
(
CREATE TABLE identity.UserDevices (
user_id BIGINT NOT NULL REFERENCES identity.Users (id),
device_id BIGINT NOT NULL REFERENCES identity.Devices (id),
linked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'on login',
unlinked_at TIMESTAMP COMMENT 'on logout',
PRIMARY KEY (user_id, device_id)
) COMMENT 'created on user login to know which users are using which devices';

CREATE TABLE identity.TrustedDevices
(
CREATE TABLE identity.TrustedDevices (
user_id BIGINT NOT NULL REFERENCES identity.Users (id),
device_id BIGINT NOT NULL REFERENCES identity.Devices (id),
name VARCHAR(255),
Expand All @@ -77,8 +71,7 @@ CREATE TABLE identity.TrustedDevices
INDEX idx_deleted_at (deleted_at)
) COMMENT 'users can add a device to their trusted ones, so they will have longer session and less security validations';

CREATE TABLE identity.AuthLogs
(
CREATE TABLE identity.AuthLogs (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT REFERENCES identity.Users (id),
email VARCHAR(255),
Expand Down
Loading

0 comments on commit e12dbef

Please sign in to comment.