Since campsite types need a media, i have to insert also images to the media relation. The best would be to use PostgreSQL’s pg_read_binary_file to read the media content from actual files when inserting the new rows, but the files need to be within the database cluster directory, or have to use an absolute path when running as a superuser to read from files outside the cluster directory, which means that it would depend on the path where i leave the files, that is different in development that in staging. To avoid that problem i can simply insert the rows using their base64 strings, with PostgreSQL’s decode. The images are kind of small, but i was worried that each change in demo.sql would duplicate that data in git, even if the change is not related to the images, because git stores the whole file; even if small, soon everything adds up. I do not care if the _final_ demo.sql is big, as this file is packaged in a different deb and is only installed in staging, so i’ve chosen to use m4 to build a single “amalgamated” SQL file from the base .sql file and the individual image files converted to base64 strings. That way, each image is individually managed by git and the base .sql file does not balloon up for each little change. Changed m4’s quotes to [[ ]] because the default ` ' was interfering with Intellij’s syntax highlighting.
43 lines
2.5 KiB
PL/PgSQL
43 lines
2.5 KiB
PL/PgSQL
-- m4_changequote(`[[', `]]')
|
||
begin;
|
||
|
||
set search_path to camper, auth, public;
|
||
|
||
alter sequence user_user_id_seq restart with 42;
|
||
insert into auth."user" (email, name, password)
|
||
values ('demo@camper', 'Demo User', 'demo')
|
||
, ('admin@camper', 'Demo Admin', 'admin')
|
||
;
|
||
|
||
alter sequence company_company_id_seq restart with 52;
|
||
insert into company (slug, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_lang_tag, legal_disclaimer)
|
||
values ('09184122-b276-4be2-9553-e4bbcbafe40d', 'Càmping les mines, S.L.U.', 'ESB17616756', 'Pescamines', parse_packed_phone_number('972 50 60 70', 'ES'), 'info@lesmines.cat', 'https://lesmines.cat/', 'C/ de l’Hort', 'Castelló d’Empúries', 'Girona', '17486', 'ES', 'EUR', 'ca', 'Càmping les mines, S.L.U. és responsable del tractament de les seves dades d’acord amb el RGPD i la LOPDGDD, i les tracta per a mantenir una relació mercantil/comercial amb vostè. Les conservarà mentre es mantingui aquesta relació i no es comunicaran a tercers. Pot exercir els drets d’accés, rectificació, portabilitat, supressió, limitació i oposició a Càmping les mines, S.L.U., amb domicili Carrer de l’Hort 71, 17486 Castelló d’Empúries o enviant un correu electrònic a info@lesmines.cat. Per a qualsevol reclamació pot acudir a agpd.es. Per a més informació pot consultar la nostra política de privacitat a lesmines.cat.');
|
||
|
||
insert into company_host (company_id, host)
|
||
values (52, 'localhost:8080')
|
||
, (52, 'camper.tandem.ws')
|
||
;
|
||
|
||
insert into company_user (company_id, user_id, role)
|
||
values (52, 42, 'employee')
|
||
, (52, 43, 'admin')
|
||
;
|
||
|
||
alter sequence media_media_id_seq restart with 62;
|
||
insert into media (company_id, original_filename, media_type, content)
|
||
values (52, 'plots.avif', 'image/avif', decode('m4_esyscmd([[base64 -w0 demo/plots.avif]])', 'base64'))
|
||
, (52, 'safari_tents.avif', 'image/avif', decode('m4_esyscmd([[base64 -w0 demo/safari_tents.avif]])', 'base64'))
|
||
, (52, 'bungalows.avif', 'image/avif', decode('m4_esyscmd([[base64 -w0 demo/bungalows.avif]])', 'base64'))
|
||
, (52, 'wooden_lodges.avif', 'image/avif', decode('m4_esyscmd([[base64 -w0 demo/wooden_lodges.avif]])', 'base64'))
|
||
;
|
||
|
||
alter sequence campsite_type_campsite_type_id_seq restart with 72;
|
||
insert into campsite_type (company_id, name, media_id, description)
|
||
values (52, 'Parceŀles', 62, '')
|
||
, (52, 'Safari Tents', 63, '')
|
||
, (52, 'Bungalows', 64, '')
|
||
, (52, 'Cabanes de fusta', 65, '')
|
||
;
|
||
|
||
commit;
|