github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/migration/v2_to_v3/2create.sql (about) 1 2 -- DO NOT EDIT - autogenerated by structgen 3 4 5 CREATE OR REPLACE FUNCTION f_delfunc (OUT func_dropped int 6 ) 7 AS $func$ 8 DECLARE 9 _sql text; 10 BEGIN 11 SELECT 12 count(*)::int, 13 'DROP FUNCTION ' || string_agg(oid::regprocedure::text, '; DROP FUNCTION ') 14 FROM 15 pg_proc 16 WHERE 17 starts_with (proname, 'structgen_validate_json') 18 AND pg_function_is_visible(oid) INTO func_dropped, 19 _sql; 20 -- only returned if trailing DROPs succeed 21 IF func_dropped > 0 THEN 22 -- only if function(s) found 23 EXECUTE _sql; 24 END IF; 25 END 26 $func$ 27 LANGUAGE plpgsql; 28 29 SELECT 30 f_delfunc (); 31 32 DROP FUNCTION f_delfunc; 33 34 CREATE TABLE aides ( 35 id serial PRIMARY KEY, 36 id_structureaide integer NOT NULL, 37 id_participant integer NOT NULL, 38 valeur real NOT NULL, 39 valide boolean NOT NULL, 40 par_jour boolean NOT NULL, 41 nb_jours_max integer NOT NULL 42 ); 43 44 CREATE OR REPLACE FUNCTION structgen_validate_json_boolean (data jsonb) 45 RETURNS boolean 46 AS $f$ 47 BEGIN 48 RETURN jsonb_typeof(data) = 'boolean'; 49 END; 50 $f$ 51 LANGUAGE 'plpgsql' 52 IMMUTABLE; 53 54 CREATE OR REPLACE FUNCTION structgen_validate_json_string (data jsonb) 55 RETURNS boolean 56 AS $f$ 57 BEGIN 58 RETURN jsonb_typeof(data) = 'string'; 59 END; 60 $f$ 61 LANGUAGE 'plpgsql' 62 IMMUTABLE; 63 64 CREATE OR REPLACE FUNCTION structgen_validate_json_number (data jsonb) 65 RETURNS boolean 66 AS $f$ 67 BEGIN 68 RETURN jsonb_typeof(data) = 'number'; 69 END; 70 $f$ 71 LANGUAGE 'plpgsql' 72 IMMUTABLE; 73 74 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2721319832 (data jsonb) 75 RETURNS boolean 76 AS $f$ 77 BEGIN 78 IF jsonb_typeof(data) != 'object' THEN 79 RETURN FALSE; 80 END IF; 81 RETURN (SELECT bool_and( 82 key IN ('rendez_vous', 'prix') 83 ) FROM jsonb_each(data)) 84 AND structgen_validate_json_string(data->'rendez_vous') 85 AND structgen_validate_json_number(data->'prix') 86 ; 87 END; 88 $f$ 89 LANGUAGE 'plpgsql' 90 IMMUTABLE; 91 92 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1080302296 (data jsonb) 93 RETURNS boolean 94 AS $f$ 95 BEGIN 96 IF jsonb_typeof(data) != 'object' THEN 97 RETURN FALSE; 98 END IF; 99 RETURN (SELECT bool_and( 100 key IN ('actif', 'commentaire', 'aller', 'retour') 101 ) FROM jsonb_each(data)) 102 AND structgen_validate_json_boolean(data->'actif') 103 AND structgen_validate_json_string(data->'commentaire') 104 AND structgen_validate_json_struct_2721319832(data->'aller') 105 AND structgen_validate_json_struct_2721319832(data->'retour') 106 ; 107 END; 108 $f$ 109 LANGUAGE 'plpgsql' 110 IMMUTABLE; 111 112 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2617578105 (data jsonb) 113 RETURNS boolean 114 AS $f$ 115 BEGIN 116 IF jsonb_typeof(data) != 'object' THEN 117 RETURN FALSE; 118 END IF; 119 RETURN (SELECT bool_and( 120 key IN ('actif', 'prix_acve', 'prix_loueur') 121 ) FROM jsonb_each(data)) 122 AND structgen_validate_json_boolean(data->'actif') 123 AND structgen_validate_json_number(data->'prix_acve') 124 AND structgen_validate_json_number(data->'prix_loueur') 125 ; 126 END; 127 $f$ 128 LANGUAGE 'plpgsql' 129 IMMUTABLE; 130 131 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2942046293 (data jsonb) 132 RETURNS boolean 133 AS $f$ 134 BEGIN 135 IF jsonb_typeof(data) != 'object' THEN 136 RETURN FALSE; 137 END IF; 138 RETURN (SELECT bool_and( 139 key IN ('bus', 'materiel_ski') 140 ) FROM jsonb_each(data)) 141 AND structgen_validate_json_struct_1080302296(data->'bus') 142 AND structgen_validate_json_struct_2617578105(data->'materiel_ski') 143 ; 144 END; 145 $f$ 146 LANGUAGE 'plpgsql' 147 IMMUTABLE; 148 149 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_118887585 (data jsonb) 150 RETURNS boolean 151 AS $f$ 152 BEGIN 153 IF jsonb_typeof(data) != 'object' THEN 154 RETURN FALSE; 155 END IF; 156 RETURN (SELECT bool_and( 157 key IN ('quantite', 'description', 'obligatoire') 158 ) FROM jsonb_each(data)) 159 AND structgen_validate_json_number(data->'quantite') 160 AND structgen_validate_json_string(data->'description') 161 AND structgen_validate_json_boolean(data->'obligatoire') 162 ; 163 END; 164 $f$ 165 LANGUAGE 'plpgsql' 166 IMMUTABLE; 167 168 CREATE OR REPLACE FUNCTION structgen_validate_json_array_struct_118887585 (data jsonb) 169 RETURNS boolean 170 AS $f$ 171 BEGIN 172 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 173 RETURN jsonb_typeof(data) = 'array' 174 AND (SELECT bool_and( structgen_validate_json_struct_118887585(value) ) FROM jsonb_array_elements(data)) 175 ; 176 END; 177 $f$ 178 LANGUAGE 'plpgsql' 179 IMMUTABLE; 180 181 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1755779154 (data jsonb) 182 RETURNS boolean 183 AS $f$ 184 BEGIN 185 IF jsonb_typeof(data) != 'object' THEN 186 RETURN FALSE; 187 END IF; 188 RETURN (SELECT bool_and( 189 key IN ('liste', 'complement') 190 ) FROM jsonb_each(data)) 191 AND structgen_validate_json_array_struct_118887585(data->'liste') 192 AND structgen_validate_json_string(data->'complement') 193 ; 194 END; 195 $f$ 196 LANGUAGE 'plpgsql' 197 IMMUTABLE; 198 199 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_690496530 (data jsonb) 200 RETURNS boolean 201 AS $f$ 202 BEGIN 203 IF jsonb_typeof(data) != 'object' THEN 204 RETURN FALSE; 205 END IF; 206 RETURN (SELECT bool_and( 207 key IN ('__locked__', 'lettre_directeur', 'liste_vetements', 'liste_participants') 208 ) FROM jsonb_each(data)) 209 AND structgen_validate_json_boolean(data->'__locked__') 210 AND structgen_validate_json_boolean(data->'lettre_directeur') 211 AND structgen_validate_json_boolean(data->'liste_vetements') 212 AND structgen_validate_json_boolean(data->'liste_participants') 213 ; 214 END; 215 $f$ 216 LANGUAGE 'plpgsql' 217 IMMUTABLE; 218 219 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1 (data jsonb) 220 RETURNS boolean 221 AS $f$ 222 BEGIN 223 IF jsonb_typeof(data) != 'object' THEN 224 RETURN FALSE; 225 END IF; 226 RETURN (SELECT bool_and( 227 TRUE 228 ) FROM jsonb_each(data)) 229 230 ; 231 END; 232 $f$ 233 LANGUAGE 'plpgsql' 234 IMMUTABLE; 235 236 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1788348674 (data jsonb) 237 RETURNS boolean 238 AS $f$ 239 BEGIN 240 IF jsonb_typeof(data) != 'object' THEN 241 RETURN FALSE; 242 END IF; 243 RETURN (SELECT bool_and( 244 key IN ('from', 'to') 245 ) FROM jsonb_each(data)) 246 AND structgen_validate_json_struct_1(data->'from') 247 AND structgen_validate_json_struct_1(data->'to') 248 ; 249 END; 250 $f$ 251 LANGUAGE 'plpgsql' 252 IMMUTABLE; 253 254 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2148407589 (data jsonb) 255 RETURNS boolean 256 AS $f$ 257 BEGIN 258 IF jsonb_typeof(data) != 'object' THEN 259 RETURN FALSE; 260 END IF; 261 RETURN (SELECT bool_and( 262 key IN ('plage_1', 'plage_2', 'prix_1', 'prix_2') 263 ) FROM jsonb_each(data)) 264 AND structgen_validate_json_struct_1788348674(data->'plage_1') 265 AND structgen_validate_json_struct_1788348674(data->'plage_2') 266 AND structgen_validate_json_number(data->'prix_1') 267 AND structgen_validate_json_number(data->'prix_2') 268 ; 269 END; 270 $f$ 271 LANGUAGE 'plpgsql' 272 IMMUTABLE; 273 274 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3786019866 (data jsonb) 275 RETURNS boolean 276 AS $f$ 277 BEGIN 278 IF jsonb_typeof(data) != 'object' THEN 279 RETURN FALSE; 280 END IF; 281 RETURN (SELECT bool_and( 282 key IN ('id', 'prix', 'statut', 'description') 283 ) FROM jsonb_each(data)) 284 AND structgen_validate_json_number(data->'id') 285 AND structgen_validate_json_number(data->'prix') 286 AND structgen_validate_json_string(data->'statut') 287 AND structgen_validate_json_string(data->'description') 288 ; 289 END; 290 $f$ 291 LANGUAGE 'plpgsql' 292 IMMUTABLE; 293 294 CREATE OR REPLACE FUNCTION structgen_validate_json_array_struct_3786019866 (data jsonb) 295 RETURNS boolean 296 AS $f$ 297 BEGIN 298 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 299 RETURN jsonb_typeof(data) = 'array' 300 AND (SELECT bool_and( structgen_validate_json_struct_3786019866(value) ) FROM jsonb_array_elements(data)) 301 ; 302 END; 303 $f$ 304 LANGUAGE 'plpgsql' 305 IMMUTABLE; 306 307 CREATE OR REPLACE FUNCTION structgen_validate_json_array_number (data jsonb) 308 RETURNS boolean 309 AS $f$ 310 BEGIN 311 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 312 RETURN jsonb_typeof(data) = 'array' 313 AND (SELECT bool_and( structgen_validate_json_number(value) ) FROM jsonb_array_elements(data)) 314 ; 315 END; 316 $f$ 317 LANGUAGE 'plpgsql' 318 IMMUTABLE; 319 320 CREATE OR REPLACE FUNCTION structgen_validate_json_array_4_number (data jsonb) 321 RETURNS boolean 322 AS $f$ 323 BEGIN 324 325 RETURN jsonb_typeof(data) = 'array' 326 AND (SELECT bool_and( structgen_validate_json_number(value) ) FROM jsonb_array_elements(data)) 327 AND jsonb_array_length(data) = 4; 328 END; 329 $f$ 330 LANGUAGE 'plpgsql' 331 IMMUTABLE; 332 333 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1454451391 (data jsonb) 334 RETURNS boolean 335 AS $f$ 336 BEGIN 337 IF jsonb_typeof(data) != 'object' THEN 338 RETURN FALSE; 339 END IF; 340 RETURN (SELECT bool_and( 341 key IN ('active', 'semaine', 'statut', 'jour', 'quotient_familial') 342 ) FROM jsonb_each(data)) 343 AND structgen_validate_json_string(data->'active') 344 AND structgen_validate_json_struct_2148407589(data->'semaine') 345 AND structgen_validate_json_array_struct_3786019866(data->'statut') 346 AND structgen_validate_json_array_number(data->'jour') 347 AND structgen_validate_json_array_4_number(data->'quotient_familial') 348 ; 349 END; 350 $f$ 351 LANGUAGE 'plpgsql' 352 IMMUTABLE; 353 354 CREATE TABLE camps ( 355 id serial PRIMARY KEY, 356 lieu varchar NOT NULL, 357 nom varchar NOT NULL, 358 prix real NOT NULL, 359 nb_places integer NOT NULL, 360 password varchar NOT NULL, 361 ouvert boolean NOT NULL, 362 nb_places_reservees integer NOT NULL, 363 numero_js varchar NOT NULL, 364 need_equilibre_gf boolean NOT NULL, 365 age_min integer NOT NULL, 366 age_max integer NOT NULL, 367 options jsonb NOT NULL CONSTRAINT options_structgen_validate_json_struct_2942046293 CHECK (structgen_validate_json_struct_2942046293(options)), 368 date_debut date NOT NULL, 369 date_fin date NOT NULL, 370 liste_vetements jsonb NOT NULL CONSTRAINT liste_vetements_structgen_validate_json_struct_1755779154 CHECK (structgen_validate_json_struct_1755779154(liste_vetements)), 371 schema_paiement varchar CHECK (schema_paiement IN ('acompte', 'total')) NOT NULL, 372 joomeo_album_id varchar NOT NULL, 373 envois jsonb NOT NULL CONSTRAINT envois_structgen_validate_json_struct_690496530 CHECK (structgen_validate_json_struct_690496530(envois)), 374 lien_compta varchar NOT NULL, 375 option_prix jsonb NOT NULL CONSTRAINT option_prix_structgen_validate_json_struct_1454451391 CHECK (structgen_validate_json_struct_1454451391(option_prix)), 376 inscription_simple boolean NOT NULL, 377 infos varchar NOT NULL 378 ); 379 380 CREATE TABLE camp_contraintes ( 381 id_camp integer NOT NULL, 382 id_contrainte integer NOT NULL 383 ); 384 385 CREATE TABLE contenu_documents ( 386 id_document integer NOT NULL, 387 contenu bytea , 388 miniature bytea 389 ); 390 391 CREATE TABLE contraintes ( 392 id serial PRIMARY KEY, 393 id_personne integer , 394 id_document integer , 395 builtin varchar CHECK (builtin IN ('autre', 'bafa', 'bafa_equiv', 'bafd', 'bafd_equiv', 'carte_id', 'carte_vitale', 'cert_med_cuisine', 'haccp', '', 'permis', 'sb', 'scolarite', 'secour', 'test_nautique', 'vaccin')) NOT NULL, 396 nom varchar NOT NULL, 397 description varchar NOT NULL, 398 max_docs integer NOT NULL, 399 jours_valide integer NOT NULL 400 ); 401 402 CREATE TABLE documents ( 403 id serial PRIMARY KEY, 404 taille integer NOT NULL, 405 nom_client varchar NOT NULL, 406 description varchar NOT NULL, 407 date_heure_modif timestamp (0) with time zone 408 ); 409 410 CREATE TABLE document_aides ( 411 id_document integer NOT NULL, 412 id_aide integer NOT NULL 413 ); 414 415 CREATE TABLE document_camps ( 416 id_document integer NOT NULL, 417 id_camp integer NOT NULL, 418 is_lettre boolean NOT NULL 419 ); 420 421 CREATE TABLE document_personnes ( 422 id_document integer NOT NULL, 423 id_personne integer NOT NULL, 424 id_contrainte integer NOT NULL 425 ); 426 427 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_4190070452 (data jsonb) 428 RETURNS boolean 429 AS $f$ 430 BEGIN 431 IF jsonb_typeof(data) != 'object' THEN 432 RETURN FALSE; 433 END IF; 434 RETURN (SELECT bool_and( 435 key IN ('id', 'date', 'amount', 'type', 'mean', 'payer_first_name', 'payer_last_name', 'payer_address', 'payer_zip_code', 'payer_city', 'payer_country', 'payer_email', 'payer_society', 'payer_is_society', 'url_receipt') 436 ) FROM jsonb_each(data)) 437 AND structgen_validate_json_string(data->'id') 438 AND structgen_validate_json_string(data->'date') 439 AND structgen_validate_json_number(data->'amount') 440 AND structgen_validate_json_string(data->'type') 441 AND structgen_validate_json_string(data->'mean') 442 AND structgen_validate_json_string(data->'payer_first_name') 443 AND structgen_validate_json_string(data->'payer_last_name') 444 AND structgen_validate_json_string(data->'payer_address') 445 AND structgen_validate_json_string(data->'payer_zip_code') 446 AND structgen_validate_json_string(data->'payer_city') 447 AND structgen_validate_json_string(data->'payer_country') 448 AND structgen_validate_json_string(data->'payer_email') 449 AND structgen_validate_json_string(data->'payer_society') 450 AND structgen_validate_json_boolean(data->'payer_is_society') 451 AND structgen_validate_json_string(data->'url_receipt') 452 ; 453 END; 454 $f$ 455 LANGUAGE 'plpgsql' 456 IMMUTABLE; 457 458 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2194933903 (data jsonb) 459 RETURNS boolean 460 AS $f$ 461 BEGIN 462 IF jsonb_typeof(data) != 'object' THEN 463 RETURN FALSE; 464 END IF; 465 RETURN (SELECT bool_and( 466 key IN ('HelloAsso') 467 ) FROM jsonb_each(data)) 468 AND structgen_validate_json_struct_4190070452(data->'HelloAsso') 469 ; 470 END; 471 $f$ 472 LANGUAGE 'plpgsql' 473 IMMUTABLE; 474 475 CREATE TABLE dons ( 476 id serial PRIMARY KEY, 477 valeur real NOT NULL, 478 mode_paiement varchar CHECK (mode_paiement IN ('ancv', '', 'cb', 'cheque', 'esp', 'helloasso', 'vir')) NOT NULL, 479 date_reception date NOT NULL, 480 recu_emis date NOT NULL, 481 infos jsonb NOT NULL CONSTRAINT infos_structgen_validate_json_struct_2194933903 CHECK (structgen_validate_json_struct_2194933903(infos)), 482 remercie boolean NOT NULL, 483 numero varchar NOT NULL, 484 affectation varchar NOT NULL 485 ); 486 487 CREATE TABLE don_donateurs ( 488 id_don integer NOT NULL, 489 id_personne integer , 490 id_organisme integer 491 ); 492 493 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3706195042 (data jsonb) 494 RETURNS boolean 495 AS $f$ 496 BEGIN 497 IF jsonb_typeof(data) != 'object' THEN 498 RETURN FALSE; 499 END IF; 500 RETURN (SELECT bool_and( 501 key IN ('Plage', 'active') 502 ) FROM jsonb_each(data)) 503 AND structgen_validate_json_struct_1788348674(data->'Plage') 504 AND structgen_validate_json_boolean(data->'active') 505 ; 506 END; 507 $f$ 508 LANGUAGE 'plpgsql' 509 IMMUTABLE; 510 511 CREATE TABLE equipiers ( 512 id serial PRIMARY KEY, 513 id_camp integer NOT NULL, 514 id_personne integer NOT NULL, 515 roles varchar[] , 516 diplome varchar CHECK (diplome IN ('agreg', 'ass_sociale', '', 'bafa', 'bafa_stag', 'bafd', 'bafd_stag', 'bapaat', 'beatep', 'bjeps', 'cap', 'deug', 'dut', 'educ_spe', 'eje', 'instit', 'mon_educ', 'prof', 'staps', 'zzautre')) NOT NULL, 517 appro varchar CHECK (appro IN ('', 'autre', 'canoe', 'moto', 'sb', 'voile')) NOT NULL, 518 presence jsonb NOT NULL CONSTRAINT presence_structgen_validate_json_struct_3706195042 CHECK (structgen_validate_json_struct_3706195042(presence)), 519 invitation_equipier integer NOT NULL, 520 charte integer CHECK (charte IN (-1, 1, 0)) NOT NULL 521 ); 522 523 CREATE TABLE equipier_contraintes ( 524 id_equipier integer NOT NULL, 525 id_contrainte integer NOT NULL, 526 optionnel boolean NOT NULL 527 ); 528 529 CREATE OR REPLACE FUNCTION structgen_validate_json_Sexe (data jsonb) 530 RETURNS boolean 531 AS $f$ 532 BEGIN 533 RETURN jsonb_typeof(data) = 'string' AND data#>>'{}' IN ('', 'F', 'M'); 534 END; 535 $f$ 536 LANGUAGE 'plpgsql' 537 IMMUTABLE; 538 539 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2287278961 (data jsonb) 540 RETURNS boolean 541 AS $f$ 542 BEGIN 543 IF jsonb_typeof(data) != 'object' THEN 544 RETURN FALSE; 545 END IF; 546 RETURN (SELECT bool_and( 547 key IN ('nom_prenom', 'sexe', 'adresse', 'code_postal', 'ville') 548 ) FROM jsonb_each(data)) 549 AND structgen_validate_json_string(data->'nom_prenom') 550 AND structgen_validate_json_Sexe(data->'sexe') 551 AND structgen_validate_json_string(data->'adresse') 552 AND structgen_validate_json_string(data->'code_postal') 553 AND structgen_validate_json_string(data->'ville') 554 ; 555 END; 556 $f$ 557 LANGUAGE 'plpgsql' 558 IMMUTABLE; 559 560 CREATE OR REPLACE FUNCTION structgen_validate_json_array_struct_2287278961 (data jsonb) 561 RETURNS boolean 562 AS $f$ 563 BEGIN 564 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 565 RETURN jsonb_typeof(data) = 'array' 566 AND (SELECT bool_and( structgen_validate_json_struct_2287278961(value) ) FROM jsonb_array_elements(data)) 567 ; 568 END; 569 $f$ 570 LANGUAGE 'plpgsql' 571 IMMUTABLE; 572 573 CREATE TABLE factures ( 574 id serial PRIMARY KEY, 575 id_personne integer NOT NULL, 576 destinataires_optionnels jsonb CONSTRAINT destinataires_optionnels_structgen_validate_json_array_struct_2287278961 CHECK (structgen_validate_json_array_struct_2287278961(destinataires_optionnels)), 577 key varchar NOT NULL, 578 copies_mails varchar[] , 579 last_connection timestamp (0) with time zone , 580 is_confirmed boolean NOT NULL, 581 is_validated boolean NOT NULL, 582 partage_adresses_ok boolean NOT NULL 583 ); 584 585 CREATE TABLE groupes ( 586 id serial PRIMARY KEY, 587 id_camp integer NOT NULL, 588 nom varchar NOT NULL, 589 plage jsonb NOT NULL CONSTRAINT plage_structgen_validate_json_struct_1788348674 CHECK (structgen_validate_json_struct_1788348674(plage)), 590 couleur varchar NOT NULL, 591 isSimple boolean NOT NULL 592 ); 593 594 CREATE TABLE groupe_contraintes ( 595 id_groupe integer NOT NULL, 596 id_contrainte integer NOT NULL 597 ); 598 599 CREATE TABLE groupe_equipiers ( 600 id_groupe integer NOT NULL, 601 id_equipier integer NOT NULL, 602 id_camp integer NOT NULL 603 ); 604 605 CREATE TABLE groupe_participants ( 606 id_participant integer NOT NULL, 607 id_groupe integer NOT NULL, 608 id_camp integer NOT NULL, 609 manuel boolean NOT NULL 610 ); 611 612 CREATE TABLE imageuploadeds ( 613 id_camp integer NOT NULL, 614 filename varchar NOT NULL, 615 lien varchar NOT NULL, 616 content bytea 617 ); 618 619 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3918138841 (data jsonb) 620 RETURNS boolean 621 AS $f$ 622 BEGIN 623 IF jsonb_typeof(data) != 'object' THEN 624 RETURN FALSE; 625 END IF; 626 RETURN (SELECT bool_and( 627 key IN ('valid', 'id', 'crypted') 628 ) FROM jsonb_each(data)) 629 AND structgen_validate_json_boolean(data->'valid') 630 AND structgen_validate_json_number(data->'id') 631 AND structgen_validate_json_string(data->'crypted') 632 ; 633 END; 634 $f$ 635 LANGUAGE 'plpgsql' 636 IMMUTABLE; 637 638 CREATE OR REPLACE FUNCTION structgen_validate_json_array_string (data jsonb) 639 RETURNS boolean 640 AS $f$ 641 BEGIN 642 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 643 RETURN jsonb_typeof(data) = 'array' 644 AND (SELECT bool_and( structgen_validate_json_string(value) ) FROM jsonb_array_elements(data)) 645 ; 646 END; 647 $f$ 648 LANGUAGE 'plpgsql' 649 IMMUTABLE; 650 651 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3524541810 (data jsonb) 652 RETURNS boolean 653 AS $f$ 654 BEGIN 655 IF jsonb_typeof(data) != 'object' THEN 656 RETURN FALSE; 657 END IF; 658 RETURN (SELECT bool_and( 659 key IN ('lienid', 'nom', 'prenom', 'sexe', 'mail', 'adresse', 'code_postal', 'ville', 'tels', 'date_naissance', 'pays') 660 ) FROM jsonb_each(data)) 661 AND structgen_validate_json_struct_3918138841(data->'lienid') 662 AND structgen_validate_json_string(data->'nom') 663 AND structgen_validate_json_string(data->'prenom') 664 AND structgen_validate_json_Sexe(data->'sexe') 665 AND structgen_validate_json_string(data->'mail') 666 AND structgen_validate_json_string(data->'adresse') 667 AND structgen_validate_json_string(data->'code_postal') 668 AND structgen_validate_json_string(data->'ville') 669 AND structgen_validate_json_array_string(data->'tels') 670 AND structgen_validate_json_struct_1(data->'date_naissance') 671 AND structgen_validate_json_string(data->'pays') 672 ; 673 END; 674 $f$ 675 LANGUAGE 'plpgsql' 676 IMMUTABLE; 677 678 CREATE OR REPLACE FUNCTION structgen_validate_json_Bus (data jsonb) 679 RETURNS boolean 680 AS $f$ 681 BEGIN 682 RETURN jsonb_typeof(data) = 'string' AND data#>>'{}' IN ('aller', 'aller_retour', '', 'retour'); 683 END; 684 $f$ 685 LANGUAGE 'plpgsql' 686 IMMUTABLE; 687 688 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_344989053 (data jsonb) 689 RETURNS boolean 690 AS $f$ 691 BEGIN 692 IF jsonb_typeof(data) != 'object' THEN 693 RETURN FALSE; 694 END IF; 695 RETURN (SELECT bool_and( 696 key IN ('need', 'mode', 'casque', 'poids', 'taille', 'pointure') 697 ) FROM jsonb_each(data)) 698 AND structgen_validate_json_string(data->'need') 699 AND structgen_validate_json_string(data->'mode') 700 AND structgen_validate_json_boolean(data->'casque') 701 AND structgen_validate_json_number(data->'poids') 702 AND structgen_validate_json_number(data->'taille') 703 AND structgen_validate_json_number(data->'pointure') 704 ; 705 END; 706 $f$ 707 LANGUAGE 'plpgsql' 708 IMMUTABLE; 709 710 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3994291279 (data jsonb) 711 RETURNS boolean 712 AS $f$ 713 BEGIN 714 IF jsonb_typeof(data) != 'object' THEN 715 RETURN FALSE; 716 END IF; 717 RETURN (SELECT bool_and( 718 key IN ('bus', 'materiel_ski') 719 ) FROM jsonb_each(data)) 720 AND structgen_validate_json_Bus(data->'bus') 721 AND structgen_validate_json_struct_344989053(data->'materiel_ski') 722 ; 723 END; 724 $f$ 725 LANGUAGE 'plpgsql' 726 IMMUTABLE; 727 728 CREATE OR REPLACE FUNCTION structgen_validate_json_Semaine (data jsonb) 729 RETURNS boolean 730 AS $f$ 731 BEGIN 732 RETURN jsonb_typeof(data) = 'string' AND data#>>'{}' IN ('', '1', '2'); 733 END; 734 $f$ 735 LANGUAGE 'plpgsql' 736 IMMUTABLE; 737 738 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2131172154 (data jsonb) 739 RETURNS boolean 740 AS $f$ 741 BEGIN 742 IF jsonb_typeof(data) != 'object' THEN 743 RETURN FALSE; 744 END IF; 745 RETURN (SELECT bool_and( 746 key IN ('semaine', 'statut', 'quotient_familial', 'jour') 747 ) FROM jsonb_each(data)) 748 AND structgen_validate_json_Semaine(data->'semaine') 749 AND structgen_validate_json_number(data->'statut') 750 AND structgen_validate_json_number(data->'quotient_familial') 751 AND structgen_validate_json_array_number(data->'jour') 752 ; 753 END; 754 $f$ 755 LANGUAGE 'plpgsql' 756 IMMUTABLE; 757 758 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3572839532 (data jsonb) 759 RETURNS boolean 760 AS $f$ 761 BEGIN 762 IF jsonb_typeof(data) != 'object' THEN 763 RETURN FALSE; 764 END IF; 765 RETURN (SELECT bool_and( 766 key IN ('lienid', 'nom', 'prenom', 'date_naissance', 'sexe', 'id_camp', 'options', 'options_prix') 767 ) FROM jsonb_each(data)) 768 AND structgen_validate_json_struct_3918138841(data->'lienid') 769 AND structgen_validate_json_string(data->'nom') 770 AND structgen_validate_json_string(data->'prenom') 771 AND structgen_validate_json_struct_1(data->'date_naissance') 772 AND structgen_validate_json_Sexe(data->'sexe') 773 AND structgen_validate_json_number(data->'id_camp') 774 AND structgen_validate_json_struct_3994291279(data->'options') 775 AND structgen_validate_json_struct_2131172154(data->'options_prix') 776 ; 777 END; 778 $f$ 779 LANGUAGE 'plpgsql' 780 IMMUTABLE; 781 782 CREATE OR REPLACE FUNCTION structgen_validate_json_array_struct_3572839532 (data jsonb) 783 RETURNS boolean 784 AS $f$ 785 BEGIN 786 IF jsonb_typeof(data) = 'null' THEN RETURN TRUE; END IF; 787 RETURN jsonb_typeof(data) = 'array' 788 AND (SELECT bool_and( structgen_validate_json_struct_3572839532(value) ) FROM jsonb_array_elements(data)) 789 ; 790 END; 791 $f$ 792 LANGUAGE 'plpgsql' 793 IMMUTABLE; 794 795 CREATE TABLE inscriptions ( 796 id serial PRIMARY KEY, 797 info varchar NOT NULL, 798 date_heure timestamp (0) with time zone , 799 copies_mails varchar[] , 800 responsable jsonb NOT NULL CONSTRAINT responsable_structgen_validate_json_struct_3524541810 CHECK (structgen_validate_json_struct_3524541810(responsable)), 801 participants jsonb CONSTRAINT participants_structgen_validate_json_array_struct_3572839532 CHECK (structgen_validate_json_array_struct_3572839532(participants)), 802 partage_adresses_ok boolean NOT NULL 803 ); 804 805 CREATE TABLE lettredirecteurs ( 806 id_camp integer NOT NULL, 807 html varchar NOT NULL, 808 use_coord_centre boolean NOT NULL, 809 show_adresse_postale boolean NOT NULL, 810 color_coord varchar NOT NULL 811 ); 812 813 CREATE TABLE messages ( 814 id serial PRIMARY KEY, 815 id_facture integer NOT NULL, 816 kind integer CHECK (kind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL, 817 created timestamp (0) with time zone , 818 modified timestamp (0) with time zone , 819 vu boolean NOT NULL 820 ); 821 822 CREATE TABLE message_attestations ( 823 id_message integer NOT NULL, 824 distribution integer CHECK (distribution IN (0, 1, 2)) NOT NULL, 825 guard_kind integer CHECK (guard_kind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL 826 ); 827 828 CREATE TABLE message_documents ( 829 id_message integer NOT NULL, 830 id_camp integer NOT NULL, 831 guardKind integer CHECK (guardKind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL 832 ); 833 834 CREATE TABLE message_messages ( 835 id_message integer NOT NULL, 836 contenu varchar NOT NULL, 837 guard_kind integer CHECK (guard_kind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL 838 ); 839 840 CREATE TABLE message_placeliberes ( 841 id_message integer NOT NULL, 842 id_participant integer NOT NULL, 843 guardKind integer CHECK (guardKind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL 844 ); 845 846 CREATE TABLE message_sondages ( 847 id_message integer NOT NULL, 848 id_camp integer NOT NULL, 849 guardKind integer CHECK (guardKind IN (3, 7, 2, 5, 4, 6, 9, 11, 10, 1, 8, 0)) NOT NULL, 850 isSimple boolean NOT NULL 851 ); 852 853 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_514333156 (data jsonb) 854 RETURNS boolean 855 AS $f$ 856 BEGIN 857 IF jsonb_typeof(data) != 'object' THEN 858 RETURN FALSE; 859 END IF; 860 RETURN (SELECT bool_and( 861 key IN ('mail', 'adresse', 'code_postal', 'ville', 'pays') 862 ) FROM jsonb_each(data)) 863 AND structgen_validate_json_string(data->'mail') 864 AND structgen_validate_json_string(data->'adresse') 865 AND structgen_validate_json_string(data->'code_postal') 866 AND structgen_validate_json_string(data->'ville') 867 AND structgen_validate_json_string(data->'pays') 868 ; 869 END; 870 $f$ 871 LANGUAGE 'plpgsql' 872 IMMUTABLE; 873 874 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2953253573 (data jsonb) 875 RETURNS boolean 876 AS $f$ 877 BEGIN 878 IF jsonb_typeof(data) != 'object' THEN 879 RETURN FALSE; 880 END IF; 881 RETURN (SELECT bool_and( 882 key IN ('pub_ete', 'pub_hiver', 'echo_rocher') 883 ) FROM jsonb_each(data)) 884 AND structgen_validate_json_number(data->'pub_ete') 885 AND structgen_validate_json_number(data->'pub_hiver') 886 AND structgen_validate_json_number(data->'echo_rocher') 887 ; 888 END; 889 $f$ 890 LANGUAGE 'plpgsql' 891 IMMUTABLE; 892 893 CREATE TABLE organismes ( 894 id serial PRIMARY KEY, 895 nom varchar NOT NULL, 896 contact_propre boolean NOT NULL, 897 contact jsonb NOT NULL CONSTRAINT contact_structgen_validate_json_struct_514333156 CHECK (structgen_validate_json_struct_514333156(contact)), 898 id_contact integer , 899 id_contact_don integer , 900 exemplaires jsonb NOT NULL CONSTRAINT exemplaires_structgen_validate_json_struct_2953253573 CHECK (structgen_validate_json_struct_2953253573(exemplaires)) 901 ); 902 903 CREATE TABLE paiements ( 904 id serial PRIMARY KEY, 905 id_facture integer NOT NULL, 906 is_acompte boolean NOT NULL, 907 is_remboursement boolean NOT NULL, 908 in_bordereau timestamp (0) with time zone , 909 label_payeur varchar NOT NULL, 910 nom_banque varchar NOT NULL, 911 mode_paiement varchar CHECK (mode_paiement IN ('ancv', '', 'cb', 'cheque', 'esp', 'helloasso', 'vir')) NOT NULL, 912 numero varchar NOT NULL, 913 valeur real NOT NULL, 914 is_invalide boolean NOT NULL, 915 date_reglement timestamp (0) with time zone , 916 details varchar NOT NULL 917 ); 918 919 CREATE OR REPLACE FUNCTION structgen_validate_json_StatutAttente (data jsonb) 920 RETURNS boolean 921 AS $f$ 922 BEGIN 923 RETURN jsonb_typeof(data) = '' AND data::int IN (1, 2, 0, 3); 924 END; 925 $f$ 926 LANGUAGE 'plpgsql' 927 IMMUTABLE; 928 929 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_3523939619 (data jsonb) 930 RETURNS boolean 931 AS $f$ 932 BEGIN 933 IF jsonb_typeof(data) != 'object' THEN 934 RETURN FALSE; 935 END IF; 936 RETURN (SELECT bool_and( 937 key IN ('statut', 'raison') 938 ) FROM jsonb_each(data)) 939 AND structgen_validate_json_StatutAttente(data->'statut') 940 AND structgen_validate_json_string(data->'raison') 941 ; 942 END; 943 $f$ 944 LANGUAGE 'plpgsql' 945 IMMUTABLE; 946 947 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_4230945022 (data jsonb) 948 RETURNS boolean 949 AS $f$ 950 BEGIN 951 IF jsonb_typeof(data) != 'object' THEN 952 RETURN FALSE; 953 END IF; 954 RETURN (SELECT bool_and( 955 key IN ('reduc_equipiers', 'reduc_enfants', 'reduc_speciale') 956 ) FROM jsonb_each(data)) 957 AND structgen_validate_json_number(data->'reduc_equipiers') 958 AND structgen_validate_json_number(data->'reduc_enfants') 959 AND structgen_validate_json_number(data->'reduc_speciale') 960 ; 961 END; 962 $f$ 963 LANGUAGE 'plpgsql' 964 IMMUTABLE; 965 966 CREATE TABLE participants ( 967 id serial PRIMARY KEY, 968 id_camp integer NOT NULL, 969 id_personne integer NOT NULL, 970 id_facture integer , 971 liste_attente jsonb NOT NULL CONSTRAINT liste_attente_structgen_validate_json_struct_3523939619 CHECK (structgen_validate_json_struct_3523939619(liste_attente)), 972 remises jsonb NOT NULL CONSTRAINT remises_structgen_validate_json_struct_4230945022 CHECK (structgen_validate_json_struct_4230945022(remises)), 973 option_prix jsonb NOT NULL CONSTRAINT option_prix_structgen_validate_json_struct_2131172154 CHECK (structgen_validate_json_struct_2131172154(option_prix)), 974 options jsonb NOT NULL CONSTRAINT options_structgen_validate_json_struct_3994291279 CHECK (structgen_validate_json_struct_3994291279(options)), 975 date_heure timestamp (0) with time zone , 976 isSimple boolean NOT NULL 977 ); 978 979 CREATE TABLE participant_equipiers ( 980 id_participant integer NOT NULL, 981 id_equipier integer NOT NULL, 982 id_groupe integer NOT NULL 983 ); 984 985 CREATE TABLE participantsimples ( 986 id serial PRIMARY KEY, 987 id_personne integer NOT NULL, 988 id_camp integer NOT NULL, 989 date_heure timestamp (0) with time zone , 990 info varchar NOT NULL, 991 isSimple boolean NOT NULL 992 ); 993 994 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1355495657 (data jsonb) 995 RETURNS boolean 996 AS $f$ 997 BEGIN 998 IF jsonb_typeof(data) != 'object' THEN 999 RETURN FALSE; 1000 END IF; 1001 RETURN (SELECT bool_and( 1002 key IN ('rubeole', 'varicelle', 'angine', 'oreillons', 'scarlatine', 'coqueluche', 'otite', 'rougeole', 'rhumatisme') 1003 ) FROM jsonb_each(data)) 1004 AND structgen_validate_json_boolean(data->'rubeole') 1005 AND structgen_validate_json_boolean(data->'varicelle') 1006 AND structgen_validate_json_boolean(data->'angine') 1007 AND structgen_validate_json_boolean(data->'oreillons') 1008 AND structgen_validate_json_boolean(data->'scarlatine') 1009 AND structgen_validate_json_boolean(data->'coqueluche') 1010 AND structgen_validate_json_boolean(data->'otite') 1011 AND structgen_validate_json_boolean(data->'rougeole') 1012 AND structgen_validate_json_boolean(data->'rhumatisme') 1013 ; 1014 END; 1015 $f$ 1016 LANGUAGE 'plpgsql' 1017 IMMUTABLE; 1018 1019 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1537811643 (data jsonb) 1020 RETURNS boolean 1021 AS $f$ 1022 BEGIN 1023 IF jsonb_typeof(data) != 'object' THEN 1024 RETURN FALSE; 1025 END IF; 1026 RETURN (SELECT bool_and( 1027 key IN ('asthme', 'alimentaires', 'medicamenteuses', 'autres', 'conduite_a_tenir') 1028 ) FROM jsonb_each(data)) 1029 AND structgen_validate_json_boolean(data->'asthme') 1030 AND structgen_validate_json_boolean(data->'alimentaires') 1031 AND structgen_validate_json_boolean(data->'medicamenteuses') 1032 AND structgen_validate_json_string(data->'autres') 1033 AND structgen_validate_json_string(data->'conduite_a_tenir') 1034 ; 1035 END; 1036 $f$ 1037 LANGUAGE 'plpgsql' 1038 IMMUTABLE; 1039 1040 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_1240729534 (data jsonb) 1041 RETURNS boolean 1042 AS $f$ 1043 BEGIN 1044 IF jsonb_typeof(data) != 'object' THEN 1045 RETURN FALSE; 1046 END IF; 1047 RETURN (SELECT bool_and( 1048 key IN ('nom', 'tel') 1049 ) FROM jsonb_each(data)) 1050 AND structgen_validate_json_string(data->'nom') 1051 AND structgen_validate_json_string(data->'tel') 1052 ; 1053 END; 1054 $f$ 1055 LANGUAGE 'plpgsql' 1056 IMMUTABLE; 1057 1058 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_4084551223 (data jsonb) 1059 RETURNS boolean 1060 AS $f$ 1061 BEGIN 1062 IF jsonb_typeof(data) != 'object' THEN 1063 RETURN FALSE; 1064 END IF; 1065 RETURN (SELECT bool_and( 1066 key IN ('traitement_medical', 'maladies', 'allergies', 'difficultes_sante', 'recommandations', 'handicap', 'tel', 'medecin', 'last_modif', 'mails') 1067 ) FROM jsonb_each(data)) 1068 AND structgen_validate_json_boolean(data->'traitement_medical') 1069 AND structgen_validate_json_struct_1355495657(data->'maladies') 1070 AND structgen_validate_json_struct_1537811643(data->'allergies') 1071 AND structgen_validate_json_string(data->'difficultes_sante') 1072 AND structgen_validate_json_string(data->'recommandations') 1073 AND structgen_validate_json_boolean(data->'handicap') 1074 AND structgen_validate_json_string(data->'tel') 1075 AND structgen_validate_json_struct_1240729534(data->'medecin') 1076 AND structgen_validate_json_struct_1(data->'last_modif') 1077 AND structgen_validate_json_array_string(data->'mails') 1078 ; 1079 END; 1080 $f$ 1081 LANGUAGE 'plpgsql' 1082 IMMUTABLE; 1083 1084 CREATE TABLE personnes ( 1085 id serial PRIMARY KEY, 1086 nom varchar NOT NULL, 1087 nom_jeune_fille varchar NOT NULL, 1088 prenom varchar NOT NULL, 1089 date_naissance date NOT NULL, 1090 ville_naissance varchar NOT NULL, 1091 departement_naissance varchar NOT NULL, 1092 sexe varchar CHECK (sexe IN ('', 'F', 'M')) NOT NULL, 1093 tels varchar[] , 1094 mail varchar NOT NULL, 1095 adresse varchar NOT NULL, 1096 code_postal varchar NOT NULL, 1097 ville varchar NOT NULL, 1098 pays varchar NOT NULL, 1099 securite_sociale varchar NOT NULL, 1100 profession varchar NOT NULL, 1101 etudiant boolean NOT NULL, 1102 fonctionnaire boolean NOT NULL, 1103 version_papier boolean NOT NULL, 1104 pub_hiver boolean NOT NULL, 1105 pub_ete boolean NOT NULL, 1106 echo_rocher boolean NOT NULL, 1107 rang_membre_asso varchar CHECK (rang_membre_asso IN ('3', '2', '1', '')) NOT NULL, 1108 quotient_familial integer NOT NULL, 1109 cotisation integer[] , 1110 eonews boolean NOT NULL, 1111 fiche_sanitaire jsonb NOT NULL CONSTRAINT fiche_sanitaire_structgen_validate_json_struct_4084551223 CHECK (structgen_validate_json_struct_4084551223(fiche_sanitaire)), 1112 is_temporaire boolean NOT NULL 1113 ); 1114 1115 CREATE TABLE sondages ( 1116 id serial PRIMARY KEY, 1117 id_camp integer NOT NULL, 1118 id_facture integer NOT NULL, 1119 modified timestamp (0) with time zone , 1120 infos_avant_sejour integer CHECK (infos_avant_sejour IN (1, 2, 3, 4, 0)) NOT NULL, 1121 infos_pendant_sejour integer CHECK (infos_pendant_sejour IN (1, 2, 3, 4, 0)) NOT NULL, 1122 hebergement integer CHECK (hebergement IN (1, 2, 3, 4, 0)) NOT NULL, 1123 activites integer CHECK (activites IN (1, 2, 3, 4, 0)) NOT NULL, 1124 theme integer CHECK (theme IN (1, 2, 3, 4, 0)) NOT NULL, 1125 nourriture integer CHECK (nourriture IN (1, 2, 3, 4, 0)) NOT NULL, 1126 hygiene integer CHECK (hygiene IN (1, 2, 3, 4, 0)) NOT NULL, 1127 ambiance integer CHECK (ambiance IN (1, 2, 3, 4, 0)) NOT NULL, 1128 ressenti integer CHECK (ressenti IN (1, 2, 3, 4, 0)) NOT NULL, 1129 message_enfant varchar NOT NULL, 1130 message_responsable varchar NOT NULL 1131 ); 1132 1133 CREATE TABLE structureaides ( 1134 id serial PRIMARY KEY, 1135 nom varchar NOT NULL, 1136 immatriculation varchar NOT NULL, 1137 adresse varchar NOT NULL, 1138 code_postal varchar NOT NULL, 1139 ville varchar NOT NULL, 1140 telephone varchar NOT NULL, 1141 info varchar NOT NULL 1142 ); 1143 1144 CREATE OR REPLACE FUNCTION structgen_validate_json_struct_2301900765 (data jsonb) 1145 RETURNS boolean 1146 AS $f$ 1147 BEGIN 1148 IF jsonb_typeof(data) != 'object' THEN 1149 RETURN FALSE; 1150 END IF; 1151 RETURN (SELECT bool_and( 1152 key IN ('personnes', 'camps', 'inscriptions', 'suivi_camps', 'suivi_dossiers', 'paiements', 'aides', 'equipiers', 'dons') 1153 ) FROM jsonb_each(data)) 1154 AND structgen_validate_json_number(data->'personnes') 1155 AND structgen_validate_json_number(data->'camps') 1156 AND structgen_validate_json_number(data->'inscriptions') 1157 AND structgen_validate_json_number(data->'suivi_camps') 1158 AND structgen_validate_json_number(data->'suivi_dossiers') 1159 AND structgen_validate_json_number(data->'paiements') 1160 AND structgen_validate_json_number(data->'aides') 1161 AND structgen_validate_json_number(data->'equipiers') 1162 AND structgen_validate_json_number(data->'dons') 1163 ; 1164 END; 1165 $f$ 1166 LANGUAGE 'plpgsql' 1167 IMMUTABLE; 1168 1169 CREATE TABLE users ( 1170 id serial PRIMARY KEY, 1171 label varchar NOT NULL, 1172 mdp varchar NOT NULL, 1173 is_admin boolean NOT NULL, 1174 modules jsonb NOT NULL CONSTRAINT modules_structgen_validate_json_struct_2301900765 CHECK (structgen_validate_json_struct_2301900765(modules)) 1175 ); 1176 ALTER TABLE aides ADD FOREIGN KEY(id_structureaide) REFERENCES structureaides ; 1177 ALTER TABLE aides ADD FOREIGN KEY(id_participant) REFERENCES participants ON DELETE CASCADE; 1178 ALTER TABLE camp_contraintes ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1179 ALTER TABLE camp_contraintes ADD FOREIGN KEY(id_contrainte) REFERENCES contraintes ; 1180 ALTER TABLE contenu_documents ADD FOREIGN KEY(id_document) REFERENCES documents ON DELETE CASCADE; 1181 ALTER TABLE contraintes ADD FOREIGN KEY(id_personne) REFERENCES personnes ON DELETE CASCADE; 1182 ALTER TABLE contraintes ADD FOREIGN KEY(id_document) REFERENCES documents ; 1183 ALTER TABLE document_aides ADD FOREIGN KEY(id_document) REFERENCES documents ON DELETE CASCADE; 1184 ALTER TABLE document_aides ADD FOREIGN KEY(id_aide) REFERENCES aides ; 1185 ALTER TABLE document_camps ADD FOREIGN KEY(id_document) REFERENCES documents ON DELETE CASCADE; 1186 ALTER TABLE document_camps ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1187 ALTER TABLE document_personnes ADD FOREIGN KEY(id_document) REFERENCES documents ON DELETE CASCADE; 1188 ALTER TABLE document_personnes ADD FOREIGN KEY(id_personne) REFERENCES personnes ; 1189 ALTER TABLE document_personnes ADD FOREIGN KEY(id_contrainte) REFERENCES contraintes ; 1190 ALTER TABLE don_donateurs ADD FOREIGN KEY(id_don) REFERENCES dons ON DELETE CASCADE; 1191 ALTER TABLE don_donateurs ADD FOREIGN KEY(id_personne) REFERENCES personnes ; 1192 ALTER TABLE don_donateurs ADD FOREIGN KEY(id_organisme) REFERENCES organismes ; 1193 ALTER TABLE equipiers ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1194 ALTER TABLE equipiers ADD FOREIGN KEY(id_personne) REFERENCES personnes ON DELETE CASCADE; 1195 ALTER TABLE equipier_contraintes ADD FOREIGN KEY(id_equipier) REFERENCES equipiers ON DELETE CASCADE; 1196 ALTER TABLE equipier_contraintes ADD FOREIGN KEY(id_contrainte) REFERENCES contraintes ; 1197 ALTER TABLE factures ADD FOREIGN KEY(id_personne) REFERENCES personnes ; 1198 ALTER TABLE groupes ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1199 ALTER TABLE groupe_contraintes ADD FOREIGN KEY(id_groupe) REFERENCES groupes ON DELETE CASCADE; 1200 ALTER TABLE groupe_contraintes ADD FOREIGN KEY(id_contrainte) REFERENCES contraintes ; 1201 ALTER TABLE groupe_equipiers ADD FOREIGN KEY(id_groupe) REFERENCES groupes ON DELETE CASCADE; 1202 ALTER TABLE groupe_equipiers ADD FOREIGN KEY(id_equipier) REFERENCES equipiers ON DELETE CASCADE; 1203 ALTER TABLE groupe_equipiers ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1204 ALTER TABLE groupe_participants ADD FOREIGN KEY(id_participant) REFERENCES participants ON DELETE CASCADE; 1205 ALTER TABLE groupe_participants ADD FOREIGN KEY(id_groupe) REFERENCES groupes ON DELETE CASCADE; 1206 ALTER TABLE groupe_participants ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1207 ALTER TABLE imageuploadeds ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1208 ALTER TABLE lettredirecteurs ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1209 ALTER TABLE messages ADD FOREIGN KEY(id_facture) REFERENCES factures ON DELETE CASCADE; 1210 ALTER TABLE message_attestations ADD FOREIGN KEY(id_message) REFERENCES messages ON DELETE CASCADE; 1211 ALTER TABLE message_documents ADD FOREIGN KEY(id_message) REFERENCES messages ON DELETE CASCADE; 1212 ALTER TABLE message_documents ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1213 ALTER TABLE message_messages ADD FOREIGN KEY(id_message) REFERENCES messages ON DELETE CASCADE; 1214 ALTER TABLE message_placeliberes ADD FOREIGN KEY(id_message) REFERENCES messages ON DELETE CASCADE; 1215 ALTER TABLE message_placeliberes ADD FOREIGN KEY(id_participant) REFERENCES participants ; 1216 ALTER TABLE message_sondages ADD FOREIGN KEY(id_message) REFERENCES messages ON DELETE CASCADE; 1217 ALTER TABLE message_sondages ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1218 ALTER TABLE organismes ADD FOREIGN KEY(id_contact) REFERENCES personnes ; 1219 ALTER TABLE organismes ADD FOREIGN KEY(id_contact_don) REFERENCES personnes ; 1220 ALTER TABLE paiements ADD FOREIGN KEY(id_facture) REFERENCES factures ; 1221 ALTER TABLE participants ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1222 ALTER TABLE participants ADD FOREIGN KEY(id_personne) REFERENCES personnes ON DELETE CASCADE; 1223 ALTER TABLE participants ADD FOREIGN KEY(id_facture) REFERENCES factures ON DELETE SET NULL; 1224 ALTER TABLE participant_equipiers ADD FOREIGN KEY(id_participant) REFERENCES participants ON DELETE CASCADE; 1225 ALTER TABLE participant_equipiers ADD FOREIGN KEY(id_equipier) REFERENCES equipiers ON DELETE CASCADE; 1226 ALTER TABLE participant_equipiers ADD FOREIGN KEY(id_groupe) REFERENCES groupes ON DELETE CASCADE; 1227 ALTER TABLE participantsimples ADD FOREIGN KEY(id_personne) REFERENCES personnes ON DELETE CASCADE; 1228 ALTER TABLE participantsimples ADD FOREIGN KEY(id_camp) REFERENCES camps ; 1229 ALTER TABLE sondages ADD FOREIGN KEY(id_camp) REFERENCES camps ON DELETE CASCADE; 1230 ALTER TABLE sondages ADD FOREIGN KEY(id_facture) REFERENCES factures ON DELETE CASCADE; 1231 ALTER TABLE camps ADD UNIQUE(id,inscription_simple); 1232 ALTER TABLE lettredirecteurs ADD UNIQUE(id_camp); 1233 ALTER TABLE imageuploadeds ADD UNIQUE(id_camp, lien); 1234 ALTER TABLE groupes ADD UNIQUE(id_camp, nom); 1235 ALTER TABLE groupes ADD UNIQUE(id, id_camp); 1236 ALTER TABLE groupes ALTER COLUMN isSimple SET DEFAULT false; 1237 ALTER TABLE groupes ADD CHECK(isSimple = false); 1238 ALTER TABLE groupes ADD FOREIGN KEY (id_camp, isSimple) REFERENCES camps(id,inscription_simple); 1239 ALTER TABLE sondages ADD UNIQUE(id_camp, id_facture); 1240 ALTER TABLE participants ADD UNIQUE(id_personne, id_camp); 1241 ALTER TABLE participants ADD UNIQUE(id, id_camp); 1242 ALTER TABLE participants ALTER COLUMN isSimple SET DEFAULT false; 1243 ALTER TABLE participants ADD CHECK(isSimple = false); 1244 ALTER TABLE participants ADD FOREIGN KEY (id_camp, isSimple) REFERENCES camps(id,inscription_simple); 1245 ALTER TABLE groupe_participants ADD UNIQUE (id_participant); 1246 ALTER TABLE groupe_participants ADD UNIQUE (id_participant, id_groupe); 1247 ALTER TABLE groupe_participants ADD FOREIGN KEY (id_participant, id_camp) REFERENCES participants(id,id_camp); 1248 ALTER TABLE groupe_participants ADD FOREIGN KEY (id_groupe, id_camp) REFERENCES groupes(id,id_camp); 1249 ALTER TABLE equipiers ADD UNIQUE(id_personne, id_camp); 1250 ALTER TABLE equipiers ADD UNIQUE(id, id_camp); 1251 ALTER TABLE groupe_equipiers ADD UNIQUE(id_groupe, id_equipier); 1252 ALTER TABLE groupe_equipiers ADD FOREIGN KEY (id_equipier, id_camp) REFERENCES equipiers(id,id_camp); 1253 ALTER TABLE groupe_equipiers ADD FOREIGN KEY (id_groupe, id_camp) REFERENCES groupes(id,id_camp); 1254 ALTER TABLE participant_equipiers ADD UNIQUE (id_participant); 1255 ALTER TABLE participant_equipiers ADD FOREIGN KEY (id_participant, id_groupe) REFERENCES groupe_participants(id_participant, id_groupe); 1256 ALTER TABLE participant_equipiers ADD FOREIGN KEY (id_equipier, id_groupe) REFERENCES groupe_equipiers(id_equipier, id_groupe) ON DELETE CASCADE; 1257 ALTER TABLE participantsimples ADD UNIQUE(id_personne, id_camp); 1258 ALTER TABLE participantsimples ALTER COLUMN isSimple SET DEFAULT TRUE; 1259 ALTER TABLE participantsimples ADD CHECK(isSimple = TRUE); 1260 ALTER TABLE participantsimples ADD FOREIGN KEY (id_camp, isSimple) REFERENCES camps(id,inscription_simple); 1261 ALTER TABLE organismes ADD CHECK(contact_propre <> (id_contact IS NOT NULL)); 1262 ALTER TABLE don_donateurs ADD CHECK(id_personne <> null OR id_organisme <> null); 1263 ALTER TABLE don_donateurs ADD CHECK(id_personne = null OR id_organisme = null); 1264 ALTER TABLE don_donateurs ADD UNIQUE(id_don); 1265 ALTER TABLE contraintes ADD UNIQUE(nom, builtin, id_personne); 1266 ALTER TABLE contraintes ADD CHECK(builtin <> '' OR id_personne IS NOT NULL); 1267 ALTER TABLE equipier_contraintes ADD UNIQUE(id_equipier, id_contrainte); 1268 ALTER TABLE camp_contraintes ADD UNIQUE(id_camp, id_contrainte); 1269 ALTER TABLE groupe_contraintes ADD UNIQUE(id_groupe, id_contrainte); 1270 ALTER TABLE contenu_documents ADD UNIQUE(id_document); 1271 ALTER TABLE document_camps ADD UNIQUE(id_document); 1272 ALTER TABLE document_personnes ADD UNIQUE(id_document); 1273 ALTER TABLE document_aides ADD UNIQUE(id_document); 1274 ALTER TABLE messages ADD UNIQUE(id, kind); 1275 CREATE FUNCTION m_responsable() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 1'; 1276 CREATE FUNCTION m_centre() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 2'; 1277 CREATE FUNCTION m_accuse_reception() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 3'; 1278 CREATE FUNCTION m_facture() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 4'; 1279 CREATE FUNCTION m_documents() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 5'; 1280 CREATE FUNCTION m_facture_acquittee() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 6'; 1281 CREATE FUNCTION m_attestation_presence() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 7'; 1282 CREATE FUNCTION m_sondage() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 8'; 1283 CREATE FUNCTION m_inscription() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 9'; 1284 CREATE FUNCTION m_place_liberee() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 10'; 1285 ALTER TABLE message_documents ADD UNIQUE(id_message); 1286 ALTER TABLE message_documents ADD CHECK(guardKind = 5); 1287 ALTER TABLE message_documents ALTER COLUMN guardKind SET DEFAULT 5; 1288 ALTER TABLE message_documents ADD FOREIGN KEY (id_message, guardKind) REFERENCES messages(id,kind); 1289 ALTER TABLE message_sondages ADD UNIQUE(id_message); 1290 ALTER TABLE message_sondages ADD CHECK(guardKind = 8); 1291 ALTER TABLE message_sondages ALTER COLUMN guardKind SET DEFAULT 8; 1292 ALTER TABLE message_sondages ADD FOREIGN KEY (id_message, guardKind) REFERENCES messages(id,kind); 1293 ALTER TABLE message_sondages ALTER COLUMN isSimple SET DEFAULT FALSE; 1294 ALTER TABLE message_sondages ADD CHECK(isSimple = FALSE); 1295 ALTER TABLE message_sondages ADD FOREIGN KEY (id_camp, isSimple) REFERENCES camps(id,inscription_simple); 1296 ALTER TABLE message_placeliberes ADD UNIQUE(id_message); 1297 ALTER TABLE message_placeliberes ADD CHECK(guardKind = 10); 1298 ALTER TABLE message_placeliberes ALTER COLUMN guardKind SET DEFAULT 10; 1299 ALTER TABLE message_placeliberes ADD FOREIGN KEY (id_message, guardKind) REFERENCES messages(id,kind); 1300 ALTER TABLE message_attestations ADD UNIQUE(id_message); 1301 ALTER TABLE message_attestations ADD CHECK(guard_kind = 6 OR guard_kind = 7); 1302 ALTER TABLE message_attestations ADD FOREIGN KEY (id_message, guard_kind) REFERENCES messages(id,kind); 1303 CREATE FUNCTION d_mail() RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS 'SELECT 1'; 1304 ALTER TABLE message_messages ADD UNIQUE(id_message); 1305 ALTER TABLE message_messages ADD CHECK(guard_kind = 1 OR guard_kind = 2); 1306 ALTER TABLE message_messages ADD FOREIGN KEY (id_message, guard_kind) REFERENCES messages(id,kind);