23 lines
777 B
MySQL
23 lines
777 B
MySQL
|
|
-- Internal tickets have a fixed, canonical customer identity.
|
||
|
|
-- Never overwrite another customer if an installation already uses ID 8.
|
||
|
|
DO $$
|
||
|
|
DECLARE
|
||
|
|
existing_name TEXT;
|
||
|
|
BEGIN
|
||
|
|
SELECT name INTO existing_name FROM customers WHERE id = 8;
|
||
|
|
|
||
|
|
IF existing_name IS NULL THEN
|
||
|
|
INSERT INTO customers (id, name, email, email_domain, country, is_active)
|
||
|
|
VALUES (8, 'BMC Networks', 'info@bmcnetworks.dk', 'bmcnetworks.dk', 'DK', TRUE);
|
||
|
|
ELSIF LOWER(TRIM(existing_name)) <> LOWER('BMC Networks') THEN
|
||
|
|
RAISE EXCEPTION 'Customer ID 8 is already used by %, expected BMC Networks', existing_name;
|
||
|
|
END IF;
|
||
|
|
END $$;
|
||
|
|
|
||
|
|
SELECT setval(
|
||
|
|
pg_get_serial_sequence('customers', 'id'),
|
||
|
|
GREATEST((SELECT COALESCE(MAX(id), 1) FROM customers), 1),
|
||
|
|
TRUE
|
||
|
|
);
|
||
|
|
|