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