Add ledger, address/contact sort, and tighter schema-graph layout.
Replace manifestarticle.transactedamount with an append-only ledger, add sort on entity address/contact, and allow same-rank FKs with crossing-aware exits in the graph.
This commit is contained in:
@@ -178,6 +178,7 @@ BEGIN
|
||||
city NVARCHAR(255) NULL,
|
||||
county NVARCHAR(255) NULL,
|
||||
addresstype NVARCHAR(50) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_entityaddress_sort DEFAULT 0,
|
||||
CONSTRAINT FK_entityaddress_entity FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE CASCADE
|
||||
);
|
||||
END
|
||||
@@ -191,6 +192,7 @@ BEGIN
|
||||
entity_id INT NOT NULL,
|
||||
contacttype NVARCHAR(50) NOT NULL,
|
||||
contact NVARCHAR(255) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_entitycontact_sort DEFAULT 0,
|
||||
CONSTRAINT FK_entitycontact_entity FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE CASCADE
|
||||
);
|
||||
END
|
||||
@@ -520,7 +522,6 @@ BEGIN
|
||||
article_id INT NULL,
|
||||
amount FLOAT NOT NULL,
|
||||
net FLOAT NOT NULL,
|
||||
transactedamount FLOAT NOT NULL,
|
||||
comment NVARCHAR(MAX) NULL,
|
||||
rebate FLOAT NOT NULL CONSTRAINT DF_manifestarticle_rebate DEFAULT 0,
|
||||
tax_id INT NOT NULL,
|
||||
@@ -531,6 +532,21 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_LEDGER = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'ledger')
|
||||
BEGIN
|
||||
CREATE TABLE ledger (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
manifestarticle_id INT NOT NULL,
|
||||
transaction_type NVARCHAR(100) NOT NULL,
|
||||
amount FLOAT NOT NULL,
|
||||
transaction_text NVARCHAR(MAX) NOT NULL,
|
||||
prev_hash NVARCHAR(128) NULL,
|
||||
CONSTRAINT FK_ledger_manifestarticle FOREIGN KEY (manifestarticle_id) REFERENCES manifestarticle(id) ON DELETE NO ACTION
|
||||
) WITH (LEDGER = ON (APPEND_ONLY = ON));
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_NUMBERS = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'numbers')
|
||||
BEGIN
|
||||
@@ -688,6 +704,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_PRICE,
|
||||
INIT_MANIFEST,
|
||||
INIT_MANIFESTARTICLE,
|
||||
INIT_LEDGER,
|
||||
INIT_NUMBERS,
|
||||
INIT_GET_NEXT_NUMBER_WITH_PREFIX_AND_PADDING,
|
||||
INIT_COMPANYUSER,
|
||||
|
||||
Reference in New Issue
Block a user