trytonpsk-hotel/migration.sql
2021-11-16 19:03:10 -05:00

54 lines
2 KiB
SQL

DROP TABLE hotel_service_line CASCADE;
DROP TABLE hotel_service CASCADE;
DROP TABLE hotel_operation_maintenance CASCADE;
ALTER TABLE hotel_booking_line RENAME TO hotel_folio;
trytond-admin -c .trytond/trytond.conf -v -d TAYLOR -u account
UPDATE hotel_folio
SET registration_card=b.registration_card
FROM hotel_booking AS b
WHERE hotel_folio.booking=b.id;
INSERT INTO booking_vouchers_rel (voucher, booking)
SELECT ov.voucher, hf.booking FROM operation_vouchers_rel AS ov
JOIN hotel_folio AS hf
ON hf.operation = ov.operation
WHERE ov.voucher NOT IN (SELECT voucher FROM booking_vouchers_rel);
DROP TABLE hotel_folio_guest;
ALTER TABLE hotel_booking_guest RENAME TO hotel_folio_guest;
ALTER TABLE hotel_folio_guest RENAME COLUMN folio TO folio_old;
ALTER TABLE hotel_folio_guest RENAME COLUMN booking_line TO folio;
INSERT INTO hotel_folio_guest (
birthday, doc_number, email, first_family_name, first_name,
folio, mobile, name, nationality, origin_country, party,
second_family_name, second_name, sex, target_country, type_document,
type_guest, type_person
)
SELECT
birthday, doc_number, email, first_family_name, first_name,
folio, mobile, name, nationality, origin_country, party,
second_family_name, second_name, sex, target_country, type_document,
type_guest, type_person
FROM dup_hotel_folio_guest WHERE id IN (3, 4, 5);
-- INSERT INTO hotel_folio_guest (folio, party)
-- SELECT fo.id AS folio, og.party AS party
-- FROM hotel_operation_guest AS og
-- JOIN hotel_folio AS fo ON fo.operation = og.operation
-- WHERE og.party NOT IN (SELECT party FROM hotel_folio_guest)
-- GROUP BY og.party, fo.id ORDER BY fo.id;
-- ALTER TABLE hotel_operation_guest RENAME TO hotel_folio;
-- DROP TABLE operation_vouchers_rel;
-- DROP TABLE hotel_folio_charge CASCADE;
-- DROP TABLE hotel_folio CASCADE;
-- DROP TABLE hotel_operation_guest CASCADE;
-- DROP TABLE hotel_operation CASCADE;
-- DROP TABLE hotel_operation_line CASCADE;