Commit 5e856e88 authored by Karamel's avatar Karamel
Browse files

Update database creation scripts, move addperpetualcs to updatedbto8.2 to...

Update database creation scripts, move addperpetualcs to updatedbto8.2 to include archive sql queries.
parent 03e0a2f0
......@@ -7,13 +7,13 @@ The semantic of version number is 'Level.Version'. Level is for compatibility be
## [Unreleased]
WARNING: this version includes changes to the database. Please read the added and changed sections carefully.
WARNING: this version includes changes to the database. Run bin/updatedbto8.2.php on each user to upgrade your databases. Please read the added and changed sections carefully.
### Added
- Archives and GPG signing. Update your databases by running res/database/<type>/addarchives.sql and add add your signing key to GPG and update your configuration file to add the fingerprint of your key (see README.md).
- Archives and GPG signing. To update, either set gpg/enabled = false in your configuration file or add your signing key to GPG and update your configuration file to add the fingerprint of your key (see README.md). Also install the new required library php-gnupg on your server to make everything working.
### Changed
- Perpetual CS is added to cash sessions. Update your databases by running bin/addperpetualcs.php on all accounts. The perpetual CS is computed server-side when writing a closed cash without including it to preserve retro-compatibility, but clients should be updated to send it along the other sums.
- Perpetual CS is added to cash sessions. The perpetual CS is computed server-side when writing a closed cash without including it to preserve retro-compatibility, but clients should be updated to send it along the other sums.
- Assigning an empty array or null does not keep an association values but clear them. To keep the actual value, do not set it in the json structure.
### Fixed
......
......@@ -39,21 +39,31 @@ if ($db === false) {
$ptApp->login($ptApp->getIdentModule()->getUser($v8User));
$em = $ptApp->getDao()->getEntityManager();
$sql = '';
$sqls = [];
switch ($db['type']) {
case 'postgresql':
case 'mysql':
$sql = 'ALTER TABLE sessions ADD csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
$sqls[] = 'ALTER TABLE sessions ADD csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
$sqls[] = 'CREATE SEQUENCE archiverequests_id_seq INCREMENT BY 1 MINVALUE 1 START 1;';
$sqls[] = 'CREATE TABLE archives (number INT NOT NULL, info TEXT NOT NULL, content BYTEA NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));';
$sqls[] = 'CREATE TABLE archiverequests (id INT NOT NULL, startDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, stopDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, processing BOOLEAN NOT NULL, PRIMARY KEY(id));';
break;
case 'mysql':
$sqls[] = 'ALTER TABLE sessions ADD csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
$sqls[] = 'CREATE TABLE archives (number INT NOT NULL, info LONGTEXT NOT NULL, content LONGBLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;';
$sqls[] = 'CREATE TABLE archiverequests (id INT AUTO_INCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;';
break;
case 'sqlite':
$sql = 'ALTER TABLE sessions ADD COLUMN csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
$sqls = 'ALTER TABLE sessions ADD COLUMN csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
$sqls = 'CREATE TABLE archives (number INTEGER NOT NULL, info CLOB NOT NULL, content BLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));';
$sqls = 'CREATE TABLE archiverequests (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing BOOLEAN NOT NULL);';
break;
default:
die(sprintf("Unknown database type %s\n", $db['type']));
}
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
foreach ($sqls as $sql) {
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
}
$crAPI = new CashregisterAPI($ptApp->getDao());
$cashRegisters = $crAPI->getAll();
......
......@@ -17,7 +17,7 @@ CREATE TABLE compositionproducts (compositiongroup_id INT NOT NULL, product_id I
CREATE TABLE cashregisters (id INT AUTO_INCREMENT NOT NULL, reference VARCHAR(255) NOT NULL, `label` VARCHAR(255) NOT NULL, nextTicketId INT NOT NULL, nextSessionId INT NOT NULL, UNIQUE INDEX UNIQ_4DC8569BAEA34913 (reference), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessionpayments (cashsession_id INT NOT NULL, paymentmode_id INT NOT NULL, currency_id INT NOT NULL, amount DOUBLE PRECISION NOT NULL, currencyAmount DOUBLE PRECISION NOT NULL, INDEX IDX_342F815C914703E (cashsession_id), INDEX IDX_342F815ABEEF95F (paymentmode_id), INDEX IDX_342F81538248176 (currency_id), PRIMARY KEY(cashsession_id, paymentmode_id, currency_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE ticketlines (ticket_id INT NOT NULL, product_id INT DEFAULT NULL, tax_id INT NOT NULL, dispOrder INT NOT NULL, productLabel VARCHAR(255) NOT NULL, unitPrice DOUBLE PRECISION DEFAULT NULL, taxedUnitPrice DOUBLE PRECISION DEFAULT NULL, quantity DOUBLE PRECISION NOT NULL, price DOUBLE PRECISION DEFAULT NULL, taxedPrice DOUBLE PRECISION NOT NULL, taxRate DOUBLE PRECISION NOT NULL, discountRate DOUBLE PRECISION NOT NULL, finalPrice DOUBLE PRECISION DEFAULT NULL, finalTaxedPrice DOUBLE PRECISION DEFAULT NULL, INDEX IDX_20FFE9B5700047D2 (ticket_id), INDEX IDX_20FFE9B54584665A (product_id), INDEX IDX_20FFE9B5B2A824D8 (tax_id), PRIMARY KEY(ticket_id, dispOrder)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessions (id INT AUTO_INCREMENT NOT NULL, cashregister_id INT NOT NULL, sequence INT NOT NULL, continuous TINYINT(1) NOT NULL, openDate DATETIME DEFAULT NULL, closeDate DATETIME DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INT DEFAULT NULL, custCount INT DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, INDEX IDX_9A609D139ED3320C (cashregister_id), UNIQUE INDEX session_index (cashregister_id, sequence), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessions (id INT AUTO_INCREMENT NOT NULL, cashregister_id INT NOT NULL, sequence INT NOT NULL, continuous TINYINT(1) NOT NULL, openDate DATETIME DEFAULT NULL, closeDate DATETIME DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INT DEFAULT NULL, custCount INT DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, csPerpetual DOUBLE PRECISION NOT NULL, INDEX IDX_9A609D139ED3320C (cashregister_id), UNIQUE INDEX session_index (cashregister_id, sequence), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE ticketpayments (ticket_id INT NOT NULL, paymentmode_id INT NOT NULL, currency_id INT NOT NULL, dispOrder INT NOT NULL, amount DOUBLE PRECISION NOT NULL, currencyAmount DOUBLE PRECISION NOT NULL, INDEX IDX_1D56231D700047D2 (ticket_id), INDEX IDX_1D56231DABEEF95F (paymentmode_id), INDEX IDX_1D56231D38248176 (currency_id), PRIMARY KEY(ticket_id, dispOrder)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE categories (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, reference VARCHAR(255) NOT NULL, `label` VARCHAR(255) NOT NULL, hasImage TINYINT(1) NOT NULL, disp_order INT NOT NULL, UNIQUE INDEX UNIQ_3AF34668AEA34913 (reference), INDEX IDX_3AF34668727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE tickettaxes (ticket_id INT NOT NULL, tax_id INT NOT NULL, taxRate DOUBLE PRECISION NOT NULL, base DOUBLE PRECISION NOT NULL, amount DOUBLE PRECISION NOT NULL, INDEX IDX_AD70C2DB700047D2 (ticket_id), INDEX IDX_AD70C2DBB2A824D8 (tax_id), PRIMARY KEY(ticket_id, tax_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
......@@ -72,3 +72,5 @@ ALTER TABLE sessioncattaxes ADD CONSTRAINT FK_E4084375C914703E FOREIGN KEY (cash
ALTER TABLE sessioncattaxes ADD CONSTRAINT FK_E4084375B2A824D8 FOREIGN KEY (tax_id) REFERENCES taxes (id);
ALTER TABLE paymentmodevalues ADD CONSTRAINT FK_4CB607B0ABEEF95F FOREIGN KEY (paymentmode_id) REFERENCES paymentmodes (id);
ALTER TABLE users ADD CONSTRAINT FK_1483A5E9D60322AC FOREIGN KEY (role_id) REFERENCES roles (id);
CREATE TABLE archives (number INT NOT NULL, info LONGTEXT NOT NULL, content LONGBLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE archiverequests (id INT AUTO_INCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE fiscaltickets (type VARCHAR(255) NOT NULL, sequence VARCHAR(255) NOT NULL, number INT NOT NULL, date DATETIME NOT NULL, content LONGTEXT NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(type, sequence, number)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE archives (number INT NOT NULL, info LONGTEXT NOT NULL, content LONGBLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE archiverequests (id INT AUTO_INCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
......@@ -51,7 +51,7 @@ CREATE TABLE ticketlines (ticket_id INT NOT NULL, product_id INT DEFAULT NULL, t
CREATE INDEX IDX_20FFE9B5700047D2 ON ticketlines (ticket_id);
CREATE INDEX IDX_20FFE9B54584665A ON ticketlines (product_id);
CREATE INDEX IDX_20FFE9B5B2A824D8 ON ticketlines (tax_id);
CREATE TABLE sessions (id INT NOT NULL, cashregister_id INT NOT NULL, sequence INT NOT NULL, continuous BOOLEAN NOT NULL, openDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, closeDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INT DEFAULT NULL, custCount INT DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, PRIMARY KEY(id));
CREATE TABLE sessions (id INT NOT NULL, cashregister_id INT NOT NULL, sequence INT NOT NULL, continuous BOOLEAN NOT NULL, openDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, closeDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INT DEFAULT NULL, custCount INT DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, csperpetual DOUBLE PRECISION NOT NULL, PRIMARY KEY(id));
CREATE INDEX IDX_9A609D139ED3320C ON sessions (cashregister_id);
CREATE UNIQUE INDEX session_index ON sessions (cashregister_id, sequence);
CREATE TABLE ticketpayments (ticket_id INT NOT NULL, paymentmode_id INT NOT NULL, currency_id INT NOT NULL, dispOrder INT NOT NULL, amount DOUBLE PRECISION NOT NULL, currencyAmount DOUBLE PRECISION NOT NULL, PRIMARY KEY(ticket_id, dispOrder));
......@@ -138,3 +138,6 @@ ALTER TABLE sessioncattaxes ADD CONSTRAINT FK_E4084375C914703E FOREIGN KEY (cash
ALTER TABLE sessioncattaxes ADD CONSTRAINT FK_E4084375B2A824D8 FOREIGN KEY (tax_id) REFERENCES taxes (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE paymentmodevalues ADD CONSTRAINT FK_4CB607B0ABEEF95F FOREIGN KEY (paymentmode_id) REFERENCES paymentmodes (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE users ADD CONSTRAINT FK_1483A5E9D60322AC FOREIGN KEY (role_id) REFERENCES roles (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE SEQUENCE archiverequests_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE archives (number INT NOT NULL, info TEXT NOT NULL, content BYTEA NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));
CREATE TABLE archiverequests (id INT NOT NULL, startDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, stopDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, processing BOOLEAN NOT NULL, PRIMARY KEY(id));
CREATE TABLE fiscaltickets (type VARCHAR(255) NOT NULL, sequence VARCHAR(255) NOT NULL, number INT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, content TEXT NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(type, sequence, number));
CREATE SEQUENCE archiverequests_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE archives (number INT NOT NULL, info TEXT NOT NULL, content BYTEA NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));
CREATE TABLE archiverequests (id INT NOT NULL, startDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, stopDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, processing BOOLEAN NOT NULL, PRIMARY KEY(id));
......@@ -18,7 +18,7 @@ CREATE INDEX IDX_62534E21B2A824D8 ON customers (tax_id);
CREATE INDEX IDX_62534E21E1BC3B58 ON customers (discountprofile_id);
CREATE INDEX IDX_62534E2154EC7A8F ON customers (tariffarea_id);
CREATE TABLE discounts (id INTEGER NOT NULL, startDate DATETIME DEFAULT NULL, endDate DATETIME DEFAULT NULL, rate DOUBLE PRECISION NOT NULL, barcode VARCHAR(255) DEFAULT NULL, barcodeType INTEGER NOT NULL, disp_order INTEGER NOT NULL, PRIMARY KEY(id));
CREATE TABLE sessions (id INTEGER NOT NULL, cashregister_id INTEGER NOT NULL, sequence INTEGER NOT NULL, continuous BOOLEAN NOT NULL, openDate DATETIME DEFAULT NULL, closeDate DATETIME DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INTEGER DEFAULT NULL, custCount INTEGER DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_9A609D139ED3320C FOREIGN KEY (cashregister_id) REFERENCES cashregisters (id) NOT DEFERRABLE INITIALLY IMMEDIATE);
CREATE TABLE sessions (id INTEGER NOT NULL, cashregister_id INTEGER NOT NULL, sequence INTEGER NOT NULL, continuous BOOLEAN NOT NULL, openDate DATETIME DEFAULT NULL, closeDate DATETIME DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INTEGER DEFAULT NULL, custCount INTEGER DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, csPerpetual DOUBLE PRECISION NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_9A609D139ED3320C FOREIGN KEY (cashregister_id) REFERENCES cashregisters (id) NOT DEFERRABLE INITIALLY IMMEDIATE);
CREATE INDEX IDX_9A609D139ED3320C ON sessions (cashregister_id);
CREATE UNIQUE INDEX session_index ON sessions (cashregister_id, sequence);
CREATE TABLE cashregisters (id INTEGER NOT NULL, reference VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, nextTicketId INTEGER NOT NULL, nextSessionId INTEGER NOT NULL, PRIMARY KEY(id));
......@@ -80,3 +80,5 @@ CREATE INDEX IDX_E4084375C914703E ON sessioncattaxes (cashsession_id);
CREATE INDEX IDX_E4084375B2A824D8 ON sessioncattaxes (tax_id);
CREATE TABLE currencies (id INTEGER NOT NULL, reference VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, symbol VARCHAR(255) NOT NULL, decimalSeparator VARCHAR(255) NOT NULL, thousandsSeparator VARCHAR(255) NOT NULL, format VARCHAR(255) NOT NULL, rate DOUBLE PRECISION NOT NULL, main BOOLEAN NOT NULL, visible BOOLEAN NOT NULL, PRIMARY KEY(id));
CREATE UNIQUE INDEX UNIQ_37C44693AEA34913 ON currencies (reference);
CREATE TABLE archives (number INTEGER NOT NULL, info CLOB NOT NULL, content BLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));
CREATE TABLE archiverequests (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing BOOLEAN NOT NULL);
CREATE TABLE fiscaltickets (type VARCHAR(255) NOT NULL, sequence VARCHAR(255) NOT NULL, number INTEGER NOT NULL, date DATETIME NOT NULL, content CLOB NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(type, sequence, number));
CREATE TABLE archives (number INTEGER NOT NULL, info CLOB NOT NULL, content BLOB NOT NULL, contentHash VARCHAR(255) NOT NULL, signature VARCHAR(255) NOT NULL, PRIMARY KEY(number));
CREATE TABLE archiverequests (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, startDate DATETIME NOT NULL, stopDate DATETIME NOT NULL, processing BOOLEAN NOT NULL);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment