fix update of sqlite3

the old code had various left overs
This commit is contained in:
Uwe Steinmann 2020-02-06 18:40:03 +01:00
parent 8f041cb072
commit 21ca19df3b

View File

@ -1,34 +1,32 @@
BEGIN;
ALTER TABLE `tblVersion` RENAME TO `__tblVersion`;
CREATE TABLE `tblVersion` (
CREATE TABLE `new_tblVersion` (
`date` TEXT default NULL,
`major` INTEGER,
`minor` INTEGER,
`subminor` INTEGER
);
INSERT INTO `tblVersion` SELECT * FROM `__tblVersion`;
INSERT INTO `new_tblVersion` SELECT * FROM `tblVersion`;
DROP TABLE `__tblVersion`;
DROP TABLE `tblVersion`;
ALTER TABLE `tblUserImages` RENAME TO `__tblUserImages`;
ALTER TABLE `new_tblVersion` RENAME TO `tblVersion`;
CREATE TABLE `tblUserImages` (
CREATE TABLE `new_tblUserImages` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE,
`image` blob NOT NULL,
`mimeType` varchar(100) NOT NULL default ''
);
INSERT INTO `tblUserImages` SELECT * FROM `__tblUserImages`;
INSERT INTO `new_tblUserImages` SELECT * FROM `tblUserImages`;
DROP TABLE `__tblUserImages`;
DROP TABLE `tblUserImages`;
ALTER TABLE `tblDocumentContent` RENAME TO `__tblDocumentContent`;
ALTER TABLE `new_tblUserImages` RENAME TO `tblUserImages`;
CREATE TABLE `tblDocumentContent` (
CREATE TABLE `new_tblDocumentContent` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`document` INTEGER NOT NULL default '0' REFERENCES `tblDocuments` (`id`),
`version` INTEGER unsigned NOT NULL,
@ -44,13 +42,13 @@ CREATE TABLE `tblDocumentContent` (
UNIQUE (`document`,`version`)
);
INSERT INTO `tblDocumentContent` SELECT * FROM `__tblDocumentContent`;
INSERT INTO `new_tblDocumentContent` SELECT * FROM `tblDocumentContent`;
DROP TABLE `__tblDocumentContent`;
DROP TABLE `tblDocumentContent`;
ALTER TABLE `tblDocumentFiles` RENAME TO `__tblDocumentFiles`;
ALTER TABLE `new_tblDocumentContent` RENAME TO `tblDocumentContent`;
CREATE TABLE `tblDocumentFiles` (
CREATE TABLE `new_tblDocumentFiles` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`document` INTEGER NOT NULL default 0 REFERENCES `tblDocuments` (`id`),
`userID` INTEGER NOT NULL default 0 REFERENCES `tblUsers` (`id`),
@ -63,17 +61,17 @@ CREATE TABLE `tblDocumentFiles` (
`mimeType` varchar(100) NOT NULL default ''
) ;
INSERT INTO `tblDocumentFiles` SELECT * FROM `__tblDocumentFiles`;
INSERT INTO `new_tblDocumentFiles` SELECT * FROM `tblDocumentFiles`;
DROP TABLE `__tblDocumentFiles`;
DROP TABLE `tblDocumentFiles`;
ALTER TABLE `new_tblDocumentFiles` RENAME TO `tblDocumentFiles`;
ALTER TABLE `tblDocumentFiles` ADD COLUMN `version` INTEGER unsigned NOT NULL DEFAULT '0';
ALTER TABLE `tblDocumentFiles` ADD COLUMN `public` INTEGER unsigned NOT NULL DEFAULT '0';
ALTER TABLE `tblUsers` RENAME TO `__tblUsers`;
CREATE TABLE `tblUsers` (
CREATE TABLE `new_tblUsers` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`login` varchar(50) default NULL,
`pwd` varchar(50) default NULL,
@ -92,39 +90,39 @@ CREATE TABLE `tblUsers` (
UNIQUE (`login`)
);
INSERT INTO `tblUsers` SELECT * FROM `__tblUsers`;
INSERT INTO `new_tblUsers` SELECT * FROM `tblUsers`;
DROP TABLE `__tblUsers`;
DROP TABLE `tblUsers`;
ALTER TABLE `tblUserPasswordRequest` RENAME TO `__tblUserPasswordRequest`;
ALTER TABLE `new_tblUsers` RENAME TO `tblUsers`;
CREATE TABLE `tblUserPasswordRequest` (
CREATE TABLE `new_tblUserPasswordRequest` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE,
`hash` varchar(50) default NULL,
`date` TEXT NOT NULL
);
INSERT INTO `tblUserPasswordRequest` SELECT * FROM `__tblUserPasswordRequest`;
INSERT INTO `new_tblUserPasswordRequest` SELECT * FROM `tblUserPasswordRequest`;
DROP TABLE `__tblUserPasswordRequest`;
DROP TABLE `tblUserPasswordRequest`;
ALTER TABLE `tblUserPasswordHistory` RENAME TO `__tblUserPasswordHistory`;
ALTER TABLE `new_tblUserPasswordRequest` RENAME TO `tblUserPasswordRequest`;
CREATE TABLE `tblUserPasswordHistory` (
CREATE TABLE `new_tblUserPasswordHistory` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE,
`pwd` varchar(50) default NULL,
`date` TEXT NOT NULL
);
INSERT INTO `tblUserPasswordHistory` SELECT * FROM `__tblUserPasswordHistory`;
INSERT INTO `new_tblUserPasswordHistory` SELECT * FROM `tblUserPasswordHistory`;
DROP TABLE `__tblUserPasswordHistory`;
DROP TABLE `tblUserPasswordHistory`;
ALTER TABLE `tblDocumentReviewLog` RENAME TO `__tblDocumentReviewLog`;
ALTER TABLE `new_tblUserPasswordHistory` RENAME TO `tblUserPasswordHistory`;
CREATE TABLE `tblDocumentReviewLog` (
CREATE TABLE `new_tblDocumentReviewLog` (
`reviewLogID` INTEGER PRIMARY KEY AUTOINCREMENT,
`reviewID` INTEGER NOT NULL default 0 REFERENCES `tblDocumentReviewers` (`reviewID`) ON DELETE CASCADE,
`status` INTEGER NOT NULL default 0,
@ -133,13 +131,13 @@ CREATE TABLE `tblDocumentReviewLog` (
`userID` INTEGER NOT NULL default 0 REFERENCES `tblUsers` (`id`) ON DELETE CASCADE
);
INSERT INTO `tblDocumentReviewLog` SELECT * FROM `__tblDocumentReviewLog`;
INSERT INTO `new_tblDocumentReviewLog` SELECT * FROM `tblDocumentReviewLog`;
DROP TABLE `__tblDocumentReviewLog`;
DROP TABLE `tblDocumentReviewLog`;
ALTER TABLE `tblDocumentStatusLog` RENAME TO `__tblDocumentStatusLog`;
ALTER TABLE `new_tblDocumentReviewLog` RENAME TO `tblDocumentReviewLog`;
CREATE TABLE `tblDocumentStatusLog` (
CREATE TABLE `new_tblDocumentStatusLog` (
`statusLogID` INTEGER PRIMARY KEY AUTOINCREMENT,
`statusID` INTEGER NOT NULL default '0' REFERENCES `tblDocumentStatus` (`statusID`) ON DELETE CASCADE,
`status` INTEGER NOT NULL default '0',
@ -148,13 +146,13 @@ CREATE TABLE `tblDocumentStatusLog` (
`userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE
) ;
INSERT INTO `tblDocumentStatusLog` SELECT * FROM `__tblDocumentStatusLog`;
INSERT INTO `new_tblDocumentStatusLog` SELECT * FROM `tblDocumentStatusLog`;
DROP TABLE `__tblDocumentStatusLog`;
DROP TABLE `tblDocumentStatusLog`;
ALTER TABLE `tblDocumentApproveLog` RENAME TO `__tblDocumentApproveLog`;
ALTER TABLE `new_tblDocumentStatusLog` RENAME TO `tblDocumentStatusLog`;
CREATE TABLE `tblDocumentApproveLog` (
CREATE TABLE `new_tblDocumentApproveLog` (
`approveLogID` INTEGER PRIMARY KEY AUTOINCREMENT,
`approveID` INTEGER NOT NULL default '0' REFERENCES `tblDocumentApprovers` (`approveID`) ON DELETE CASCADE,
`status` INTEGER NOT NULL default '0',
@ -163,13 +161,13 @@ CREATE TABLE `tblDocumentApproveLog` (
`userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE
);
INSERT INTO `tblDocumentApproveLog` SELECT * FROM `__tblDocumentApproveLog`;
INSERT INTO `new_tblDocumentApproveLog` SELECT * FROM `tblDocumentApproveLog`;
DROP TABLE `__tblDocumentApproveLog`;
DROP TABLE `tblDocumentApproveLog`;
ALTER TABLE `tblWorkflowLog` RENAME TO `__tblWorkflowLog`;
ALTER TABLE `new_tblDocumentApproveLog` RENAME TO `tblDocumentApproveLog`;
CREATE TABLE `tblWorkflowLog` (
CREATE TABLE `new_tblWorkflowLog` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`document` INTEGER default NULL REFERENCES `tblDocuments` (`id`) ON DELETE CASCADE,
`version` INTEGER default NULL,
@ -180,13 +178,13 @@ CREATE TABLE `tblWorkflowLog` (
`comment` text
);
INSERT INTO `tblWorkflowLog` SELECT * FROM `__tblWorkflowLog`;
INSERT INTO `new_tblWorkflowLog` SELECT * FROM `tblWorkflowLog`;
DROP TABLE `__tblWorkflowLog`;
DROP TABLE `tblWorkflowLog`;
ALTER TABLE `tblWorkflowDocumentContent` RENAME TO `__tblWorkflowDocumentContent`;
ALTER TABLE `new_tblWorkflowLog` RENAME TO `tblWorkflowLog`;
CREATE TABLE `tblWorkflowDocumentContent` (
CREATE TABLE `new_tblWorkflowDocumentContent` (
`parentworkflow` INTEGER DEFAULT 0,
`workflow` INTEGER DEFAULT NULL REFERENCES `tblWorkflows` (`id`) ON DELETE CASCADE,
`document` INTEGER DEFAULT NULL REFERENCES `tblDocuments` (`id`) ON DELETE CASCADE,
@ -195,9 +193,11 @@ CREATE TABLE `tblWorkflowDocumentContent` (
`date` datetime NOT NULL
);
INSERT INTO `tblWorkflowDocumentContent` SELECT * FROM `__tblWorkflowDocumentContent`;
INSERT INTO `new_tblWorkflowDocumentContent` SELECT * FROM `tblWorkflowDocumentContent`;
DROP TABLE `__tblWorkflowDocumentContent`;
DROP TABLE `tblWorkflowDocumentContent`;
ALTER TABLE `new_tblWorkflowDocumentContent` RENAME TO `tblWorkflowDocumentContent`;
UPDATE tblVersion set major=5, minor=1, subminor=0;