Koha/installer/data/mysql/atomicupdate/bug_14826.sql
Kyle M Hall 2dd0d6c359 Bug 14826: (QA follow-up) Make db update idempotent
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-20 17:14:33 -03:00

31 lines
1.4 KiB
SQL

DROP TABLE IF EXISTS `accountoffsets`;
CREATE TABLE IF NOT EXISTS `account_offset_types` (
`type` varchar(16) NOT NULL, -- The type of offset this is
PRIMARY KEY (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE IF NOT EXISTS `account_offsets` (
`id` int(11) NOT NULL auto_increment, -- unique identifier for each offset
`credit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline the increased the patron's balance
`debit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline that decreased the patron's balance
`type` varchar(16) NOT NULL, -- The type of offset this is
`amount` decimal(26,6) NOT NULL, -- The amount of the change
`created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
CONSTRAINT `account_offsets_ibfk_p` FOREIGN KEY (`credit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `account_offsets_ibfk_t` FOREIGN KEY (`type`) REFERENCES `account_offset_types` (`type`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT IGNORE INTO account_offset_types ( type ) VALUES
('Writeoff'),
('Payment'),
('Lost Item'),
('Manual Debit'),
('Reverse Payment'),
('Forgiven'),
('Dropbox'),
('Rental Fee'),
('Fine Update'),
('Fine');