Updated the SQL template to include some cost of ownership information, at least the first draft of the concept.
This commit is contained in:
@@ -12,15 +12,16 @@ import (
|
|||||||
|
|
||||||
//Go Best practices: https://github.com/golovers/effective-go
|
//Go Best practices: https://github.com/golovers/effective-go
|
||||||
type Item struct {
|
type Item struct {
|
||||||
ID int32 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name int32 `json:"name"`
|
Name string `json:"name"`
|
||||||
ValueCents int32 `json:"valueCents"`
|
ValueCents int64 `json:"valueCents"`
|
||||||
PurchaseCostCents int32 `json:"purchasedCostCents"`
|
PurchaseCostCents int64 `json:"purchasedCostCents"`
|
||||||
Aquired time.Time `json:"aquired"`
|
Aquired time.Time `json:"aquired"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
SoldForCents int32 `json:"soldForCents"`
|
SoldForCents int64 `json:"soldForCents"`
|
||||||
SoldTo string `json:"soldTo"`
|
SoldTo string `json:"soldTo"`
|
||||||
|
Quantity int64 `json:"quantity"`
|
||||||
Category Category `json:"category"`
|
Category Category `json:"category"`
|
||||||
Subcategory Subcategory `json:"subcategory"`
|
Subcategory Subcategory `json:"subcategory"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
-- Version 0.5.5.1 Removed character length restrictions as the docs for POSTGRESQL recommend not specifying a limit.
|
-- Version 0.5.5.1 Removed character length restrictions as the docs for POSTGRESQL recommend not specifying a limit.
|
||||||
-- Version 0.6.0.0 Changed the numeric values to integers as Golang doesn't have a native decimal type.
|
-- Version 0.6.0.0 Changed the numeric values to integers as Golang doesn't have a native decimal type.
|
||||||
|
-- Version 0.6.2.0 Added the first draft for cost of ownership. Added quantity to the item table.
|
||||||
|
-- Version 0.6.5.0 Added a documents table along with the tables to reference them as either an expense or as a document for an item.
|
||||||
|
|
||||||
DROP TABLE IF EXISTS property_value;
|
DROP TABLE IF EXISTS property_value;
|
||||||
DROP TABLE IF EXISTS property;
|
DROP TABLE IF EXISTS property;
|
||||||
DROP TABLE IF EXISTS property_data_type;
|
DROP TABLE IF EXISTS property_data_type;
|
||||||
DROP TABLE IF EXISTS item_component;
|
DROP TABLE IF EXISTS item_component;
|
||||||
|
DROP TABLE IF EXISTS coo_document;
|
||||||
|
DROP TABLE IF EXISTS item_document;
|
||||||
|
DROP TABLE IF EXISTS document_file;
|
||||||
|
DROP TABLE IF EXISTS coo_line_item;
|
||||||
|
DROP TABLE IF EXISTS cost_of_ownership;
|
||||||
|
DROP TABLE IF EXISTS expense_type;
|
||||||
DROP TABLE IF EXISTS item;
|
DROP TABLE IF EXISTS item;
|
||||||
DROP TABLE IF EXISTS subcategory;
|
DROP TABLE IF EXISTS subcategory;
|
||||||
DROP TABLE IF EXISTS category;
|
DROP TABLE IF EXISTS category;
|
||||||
|
DROP TABLE IF EXISTS document_type;
|
||||||
|
|
||||||
CREATE TABLE property_data_type (
|
CREATE TABLE property_data_type (
|
||||||
property_data_type_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
property_data_type_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
@@ -40,6 +49,7 @@ CREATE TABLE item (
|
|||||||
notes CHARACTER VARYING,
|
notes CHARACTER VARYING,
|
||||||
sold_for_cents INT DEFAULT 0,
|
sold_for_cents INT DEFAULT 0,
|
||||||
sold_to CHARACTER VARYING, -- Could be a pointer TO a TABLE OF comtacts.
|
sold_to CHARACTER VARYING, -- Could be a pointer TO a TABLE OF comtacts.
|
||||||
|
quantity INT DEFAULT 1,
|
||||||
category_id INT NOT NULL REFERENCES category(category_id),
|
category_id INT NOT NULL REFERENCES category(category_id),
|
||||||
subcategory_id INT REFERENCES subcategory(subcategory_id)
|
subcategory_id INT REFERENCES subcategory(subcategory_id)
|
||||||
);
|
);
|
||||||
@@ -47,7 +57,7 @@ CREATE TABLE item (
|
|||||||
-- Example: property_name of "Author" which maps to property_data_type of "Text".
|
-- Example: property_name of "Author" which maps to property_data_type of "Text".
|
||||||
CREATE TABLE property (
|
CREATE TABLE property (
|
||||||
property_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
property_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
property_name CHARACTER varying NOT NULL,
|
property_name CHARACTER VARYING NOT NULL,
|
||||||
property_type_id INT NOT NULL REFERENCES property_data_type(property_data_type_id),
|
property_type_id INT NOT NULL REFERENCES property_data_type(property_data_type_id),
|
||||||
category_id INT NOT NULL REFERENCES category(category_id),
|
category_id INT NOT NULL REFERENCES category(category_id),
|
||||||
subcategory_id INT REFERENCES subcategory(subcategory_id)
|
subcategory_id INT REFERENCES subcategory(subcategory_id)
|
||||||
@@ -67,6 +77,75 @@ CREATE TABLE property_value (
|
|||||||
value CHARACTER VARYING NOT NULL
|
value CHARACTER VARYING NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE cost_of_ownership (
|
||||||
|
coo_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
coo_description CHARACTER VARYING,
|
||||||
|
coo_display_text CHARACTER VARYING NOT NULL, -- I.E. "Transmission Rebuild" etc.
|
||||||
|
coo_service_rendered_date TIMESTAMP WITH TIME ZONE
|
||||||
|
--service BIT Like was this a service or did you buy a replacement and do it yourself?
|
||||||
|
|
||||||
|
--coo type eg 'Regular Maintence' etc
|
||||||
|
);
|
||||||
|
|
||||||
|
-- An item or items associated with the cost of ownership, i.e. a replacement motor.
|
||||||
|
--CREATE TABLE coo_item (
|
||||||
|
-- coo_item_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
-- item_id INT NOT NULL REFERENCES item(item_id),
|
||||||
|
-- coo_id INT NOT NULL REFERENCES cost_of_ownership(coo_id),
|
||||||
|
--
|
||||||
|
--)
|
||||||
|
|
||||||
|
CREATE TABLE expense_type (
|
||||||
|
expense_type_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
expense_type_name CHARACTER VARYING UNIQUE NOT NULL --LIKE "Sales Tax" OR "Labour"
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO expense_type (expense_type_name) VALUES ('Sales Tax');
|
||||||
|
INSERT INTO expense_type (expense_type_name) VALUES ('Labour');
|
||||||
|
INSERT INTO expense_type (expense_type_name) VALUES ('Grand Total');
|
||||||
|
|
||||||
|
-- An itemized expense, like cost of labour, or cost of parts for whoever is doing the repairs / replacement, taxes etc..
|
||||||
|
CREATE TABLE coo_line_item (
|
||||||
|
coo_line_item_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
cost_cents INT DEFAULT 0,
|
||||||
|
expense_type_id INT NOT NULL REFERENCES expense_type(expense_type_id),
|
||||||
|
coo_id INT NOT NULL REFERENCES cost_of_ownership(coo_id),
|
||||||
|
item_id INT REFERENCES item(item_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE document_type (
|
||||||
|
document_type_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
document_type_name CHARACTER VARYING UNIQUE NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Certificate of Authenticity');
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Sales Contract');
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Invoice');
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Title');
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Deed');
|
||||||
|
INSERT INTO document_type (document_type_name) VALUES ('Receipt');
|
||||||
|
|
||||||
|
CREATE TABLE document_file (
|
||||||
|
document_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
original_filename CHARACTER VARYING NOT NULL,
|
||||||
|
display_name CHARACTER VARYING NOT NULL,
|
||||||
|
mime_type CHARACTER VARYING NOT NULL,
|
||||||
|
file_extension CHARACTER VARYING NOT NULL,
|
||||||
|
document_type_id INT NOT NULL REFERENCES document_type(document_type_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE item_document (
|
||||||
|
item_document_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
item_id INT NOT NULL REFERENCES item(item_id),
|
||||||
|
document_file_id INT NOT NULL REFERENCES document_file(document_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE coo_document (
|
||||||
|
coo_document_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||||
|
coo_id INT NOT NULL REFERENCES cost_of_ownership(coo_id),
|
||||||
|
document_file_id INT NOT NULL REFERENCES document_file(document_id)
|
||||||
|
);
|
||||||
|
|
||||||
INSERT INTO category (category_name) VALUES ('Books');
|
INSERT INTO category (category_name) VALUES ('Books');
|
||||||
INSERT INTO category (category_name) VALUES ('Electronics');
|
INSERT INTO category (category_name) VALUES ('Electronics');
|
||||||
INSERT INTO category (category_name) VALUES ('Appliances');
|
INSERT INTO category (category_name) VALUES ('Appliances');
|
||||||
|
|||||||
Reference in New Issue
Block a user