From 2894efaf46d74b647b63374211cdd81b84036c81 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 13 Oct 2015 16:03:18 -0700 Subject: [PATCH] Drop soft-delete Fixes #13. --- migrations/00001_AddUsers_up.sql | 1 - migrations/00003_AddSpecies_up.sql | 5 +---- migrations/00004_AddStrain_up.sql | 5 +---- migrations/00005_AddCharacteristicTypes_up.sql | 5 +---- migrations/00006_AddCharacteristics_up.sql | 5 +---- models/characteristics.go | 2 -- models/species.go | 2 -- models/strains.go | 2 -- models/users.go | 16 +++++----------- 9 files changed, 9 insertions(+), 34 deletions(-) diff --git a/migrations/00001_AddUsers_up.sql b/migrations/00001_AddUsers_up.sql index b706f90..c16678c 100644 --- a/migrations/00001_AddUsers_up.sql +++ b/migrations/00001_AddUsers_up.sql @@ -16,7 +16,6 @@ CREATE TABLE users ( created_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, CONSTRAINT users_pkey PRIMARY KEY (id) ); diff --git a/migrations/00003_AddSpecies_up.sql b/migrations/00003_AddSpecies_up.sql index e981487..4bc26a7 100644 --- a/migrations/00003_AddSpecies_up.sql +++ b/migrations/00003_AddSpecies_up.sql @@ -11,18 +11,15 @@ CREATE TABLE species ( created_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, created_by BIGINT NOT NULL, updated_by BIGINT NOT NULL, - deleted_by BIGINT NULL, CONSTRAINT species_pkey PRIMARY KEY (id), FOREIGN KEY (genus_id) REFERENCES genera(id), FOREIGN KEY (subspecies_species_id) REFERENCES species(id), FOREIGN KEY (created_by) REFERENCES users(id), - FOREIGN KEY (updated_by) REFERENCES users(id), - FOREIGN KEY (deleted_by) REFERENCES users(id) + FOREIGN KEY (updated_by) REFERENCES users(id) ); CREATE INDEX genus_id_idx ON species (genus_id); diff --git a/migrations/00004_AddStrain_up.sql b/migrations/00004_AddStrain_up.sql index b0f8c04..180d316 100644 --- a/migrations/00004_AddStrain_up.sql +++ b/migrations/00004_AddStrain_up.sql @@ -14,17 +14,14 @@ CREATE TABLE strains ( created_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, created_by BIGINT NOT NULL, updated_by BIGINT NOT NULL, - deleted_by BIGINT NULL, CONSTRAINT strain_pkey PRIMARY KEY (id), FOREIGN KEY (species_id) REFERENCES species(id) ON DELETE CASCADE, FOREIGN KEY (created_by) REFERENCES users(id), - FOREIGN KEY (updated_by) REFERENCES users(id), - FOREIGN KEY (deleted_by) REFERENCES users(id) + FOREIGN KEY (updated_by) REFERENCES users(id) ); CREATE INDEX species_id_idx ON strains (species_id); diff --git a/migrations/00005_AddCharacteristicTypes_up.sql b/migrations/00005_AddCharacteristicTypes_up.sql index 42222dc..ba583af 100644 --- a/migrations/00005_AddCharacteristicTypes_up.sql +++ b/migrations/00005_AddCharacteristicTypes_up.sql @@ -7,15 +7,12 @@ CREATE TABLE characteristic_types ( created_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, created_by BIGINT NOT NULL, updated_by BIGINT NOT NULL, - deleted_by BIGINT NULL, CONSTRAINT characteristic_types_pkey PRIMARY KEY (id), FOREIGN KEY (created_by) REFERENCES users(id), - FOREIGN KEY (updated_by) REFERENCES users(id), - FOREIGN KEY (deleted_by) REFERENCES users(id) + FOREIGN KEY (updated_by) REFERENCES users(id) ); diff --git a/migrations/00006_AddCharacteristics_up.sql b/migrations/00006_AddCharacteristics_up.sql index 62b7d4f..6bebbb2 100644 --- a/migrations/00006_AddCharacteristics_up.sql +++ b/migrations/00006_AddCharacteristics_up.sql @@ -9,17 +9,14 @@ CREATE TABLE characteristics ( created_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, created_by BIGINT NOT NULL, updated_by BIGINT NOT NULL, - deleted_by BIGINT NULL, CONSTRAINT characteristics_pkey PRIMARY KEY (id), FOREIGN KEY (characteristic_type_id) REFERENCES characteristic_types(id), FOREIGN KEY (created_by) REFERENCES users(id), - FOREIGN KEY (updated_by) REFERENCES users(id), - FOREIGN KEY (deleted_by) REFERENCES users(id) + FOREIGN KEY (updated_by) REFERENCES users(id) ); CREATE INDEX characteristic_type_id_idx ON characteristics (characteristic_type_id); diff --git a/models/characteristics.go b/models/characteristics.go index 8d73f84..99cc7eb 100644 --- a/models/characteristics.go +++ b/models/characteristics.go @@ -64,10 +64,8 @@ type CharacteristicBase struct { SortOrder types.NullInt64 `db:"sort_order" json:"sortOrder"` CreatedAt types.NullTime `db:"created_at" json:"createdAt"` UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"` - DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"` CreatedBy int64 `db:"created_by" json:"createdBy"` UpdatedBy int64 `db:"updated_by" json:"updatedBy"` - DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"` } // Characteristic is what the DB expects for read operations, and is what the API diff --git a/models/species.go b/models/species.go index 62a5e8a..9ed1b5b 100644 --- a/models/species.go +++ b/models/species.go @@ -67,10 +67,8 @@ type SpeciesBase struct { Etymology types.NullString `db:"etymology" json:"etymology"` CreatedAt types.NullTime `db:"created_at" json:"createdAt"` UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"` - DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"` CreatedBy int64 `db:"created_by" json:"createdBy"` UpdatedBy int64 `db:"updated_by" json:"updatedBy"` - DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"` } // Species is what the DB expects for read operations, and is what the API expects diff --git a/models/strains.go b/models/strains.go index 6420878..a7653ab 100644 --- a/models/strains.go +++ b/models/strains.go @@ -70,10 +70,8 @@ type StrainBase struct { Notes types.NullString `db:"notes" json:"notes"` CreatedAt types.NullTime `db:"created_at" json:"createdAt"` UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"` - DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"` CreatedBy int64 `db:"created_by" json:"createdBy"` UpdatedBy int64 `db:"updated_by" json:"updatedBy"` - DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"` } // Strain is what the DB expects for read operations, and is what the API expects diff --git a/models/users.go b/models/users.go index 5f18d45..17b0ddb 100644 --- a/models/users.go +++ b/models/users.go @@ -76,7 +76,6 @@ type UserBase struct { Verified bool `db:"verified" json:"-"` CreatedAt types.NullTime `db:"created_at" json:"createdAt"` UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"` - DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"` } // User is what the DB expects to see for read operations, and is what the API @@ -109,8 +108,7 @@ func DbAuthenticate(email string, password string) error { q := `SELECT * FROM users WHERE lower(email)=lower($1) - AND verified IS TRUE - AND deleted_at IS NULL;` + AND verified IS TRUE;` if err := DBH.SelectOne(&user, q, email); err != nil { return errors.ErrInvalidEmailOrPassword } @@ -126,8 +124,7 @@ func GetUser(id int64, dummy string, claims *types.Claims) (*User, error) { q := `SELECT * FROM users WHERE id=$1 - AND verified IS TRUE - AND deleted_at IS NULL;` + AND verified IS TRUE;` if err := DBH.SelectOne(&user, q, id); err != nil { if err == sql.ErrNoRows { return nil, errors.ErrUserNotFound @@ -147,8 +144,7 @@ func DbGetUserByEmail(email string) (*User, error) { q := `SELECT * FROM users WHERE lower(email)=lower($1) - AND verified IS TRUE - AND deleted_at IS NULL;` + AND verified IS TRUE;` if err := DBH.SelectOne(&user, q, email); err != nil { if err == sql.ErrNoRows { return nil, errors.ErrUserNotFound @@ -160,11 +156,9 @@ func DbGetUserByEmail(email string) (*User, error) { // ListUsers returns all users. func ListUsers(opt helpers.ListOptions, claims *types.Claims) (*Users, error) { - q := `SELECT id, email, 'password' AS password, name, role, created_at, - updated_at, deleted_at + q := `SELECT id, email, 'password' AS password, name, role, created_at, updated_at FROM users - WHERE verified IS TRUE - AND deleted_at IS NULL;` + WHERE verified IS TRUE;` users := make(Users, 0) if err := DBH.Select(&users, q); err != nil {