Changeset 947 for LATMOS-Accounts


Ignore:
Timestamp:
04/26/12 18:58:34 (12 years ago)
Author:
nanardon
Message:
  • réellement modifier la-sql-upgrade
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/bin/la-sql-upgrade.in

    r920 r947  
    5959        ver => 3, 
    6060        sql => [ 
    61         q{ALTER TABLE nethost_attributes_ips DROP CONSTRAINT 
     61            q{ALTER TABLE nethost_attributes_ips DROP CONSTRAINT 
    6262            nethost_is_single_ip}, 
    63         q{DROP TRIGGER IF EXISTS check_zone_name_unity_tg ON nethost}, 
    64         q{DROP TRIGGER IF EXISTS check_zone_name_unity_tg ON netzone}, 
    65         q{DROP FUNCTION IF EXISTS check_zone_name_unity()}, 
    66         q{ALTER TABLE nethost_attributes_ips DROP CONSTRAINT 
    67           nethost_is_single_ip}, 
    68         q{INSERT INTO settings(varname, val) VALUES ('schema_version', 3)}, 
     63            q{DROP TRIGGER IF EXISTS check_zone_name_unity_tg ON nethost}, 
     64            q{DROP TRIGGER IF EXISTS check_zone_name_unity_tg ON netzone}, 
     65            q{DROP FUNCTION IF EXISTS check_zone_name_unity()}, 
     66            q{ALTER TABLE nethost_attributes_ips DROP CONSTRAINT 
     67            nethost_is_single_ip}, 
     68            q{INSERT INTO settings(varname, val) VALUES ('schema_version', 3)}, 
    6969        ], 
    7070    }, 
     
    7474            q{ 
    7575            CREATE OR REPLACE FUNCTION nethost_sort_fields() 
    76               RETURNS trigger AS 
    77               $BODY$BEGIN 
    78  
    79               IF (TG_OP='INSERT') then 
    80               IF (new.attr='ip') THEN 
    81               insert into nethost_attributes_ips VALUES (new.*); 
    82               RETURN NULL; 
    83               END IF; 
    84  
    85               IF (new.attr='macaddr') THEN 
    86               insert into nethost_attributes_macs VALUES (new.*); 
    87               RETURN NULL; 
    88               END IF; 
    89  
    90               IF (new.attr='owner') THEN 
    91               insert into nethost_attributes_users VALUES (new.*); 
    92               RETURN NULL; 
    93               END IF; 
    94  
    95               IF (new.attr='user') THEN 
    96               insert into nethost_attributes_users VALUES (new.*); 
    97               RETURN NULL; 
    98               END IF; 
    99               end if; 
    100  
    101  
    102               if (TG_OP='DELETE') THEN 
    103               RETURN old; 
    104               else 
    105               RETURN new; 
    106               end if; 
    107               END;$BODY$ 
     76            RETURNS trigger AS 
     77            $BODY$BEGIN 
     78 
     79            IF (TG_OP='INSERT') then 
     80            IF (new.attr='ip') THEN 
     81            insert into nethost_attributes_ips VALUES (new.*); 
     82            RETURN NULL; 
     83            END IF; 
     84 
     85            IF (new.attr='macaddr') THEN 
     86            insert into nethost_attributes_macs VALUES (new.*); 
     87            RETURN NULL; 
     88            END IF; 
     89 
     90            IF (new.attr='owner') THEN 
     91            insert into nethost_attributes_users VALUES (new.*); 
     92            RETURN NULL; 
     93            END IF; 
     94 
     95            IF (new.attr='user') THEN 
     96            insert into nethost_attributes_users VALUES (new.*); 
     97            RETURN NULL; 
     98            END IF; 
     99            end if; 
     100 
     101 
     102            if (TG_OP='DELETE') THEN 
     103            RETURN old; 
     104            else 
     105            RETURN new; 
     106            end if; 
     107            END;$BODY$ 
    108108            LANGUAGE plpgsql VOLATILE 
    109109            COST 100; 
     
    111111        ], 
    112112    }, 
     113    { 
     114        ver => 5, 
     115        sql => [ 
     116            q{ 
     117            CREATE OR REPLACE VIEW address_attributes AS  
     118            ( ( SELECT address."user" AS value, 'user' AS attr, address.rev AS attr_key, address.ikey AS okey 
     119            FROM address 
     120            UNION ALL  
     121            SELECT address.name AS value, 'name' AS attr, address.rev AS attr_key, address.ikey AS okey 
     122            FROM address ) 
     123            UNION ALL 
     124            SELECT address_attributes.value, address_attributes.attr, address_attributes.attr_key, address_attributes.okey 
     125            FROM address_attributes_base address_attributes ) 
     126            UNION ALL 
     127            SELECT '1' AS value, 'active' AS attr, address.rev AS attr_key, address.ikey AS okey 
     128            FROM "user" JOIN address ON "user".name = address."user" 
     129            WHERE "user".exported AND address.exported and  
     130            ("user".expire IS NULL or "user".expire > now()) 
     131            } 
     132        ], 
     133    }, 
     134    { 
     135        ver => 6, 
     136        sql => [ 
     137            q{ 
     138            CREATE TABLE request 
     139            ( 
     140                id serial NOT NULL, 
     141                "create" timestamp with time zone NOT NULL DEFAULT now(), 
     142                name text NOT NULL, 
     143                object text, 
     144                apply timestamp with time zone NOT NULL DEFAULT now(), 
     145                done timestamp with time zone, 
     146                "user" text, 
     147                CONSTRAINT request_pkey PRIMARY KEY (id ), 
     148                CONSTRAINT request_name_fkey FOREIGN KEY (name) 
     149                REFERENCES accreq (name) MATCH SIMPLE 
     150                ON UPDATE CASCADE ON DELETE CASCADE, 
     151                CONSTRAINT request_user_fkey FOREIGN KEY ("user") 
     152                REFERENCES "user" (name) MATCH SIMPLE 
     153                ON UPDATE CASCADE ON DELETE SET NULL 
     154            ) 
     155            }, 
     156            q{ 
     157            CREATE INDEX fki_request_name_fkey ON request 
     158            USING btree (name ) 
     159            }, 
     160            q{ 
     161            CREATE INDEX fki_request_user_fkey ON request 
     162            USING btree ("user" ) 
     163            }, 
     164            q{ 
     165            CREATE TABLE request_attributes 
     166            ( 
     167                reqid bigint, 
     168                attribute text NOT NULL, 
     169                value text, 
     170                CONSTRAINT request_id_fkey FOREIGN KEY (reqid) 
     171                REFERENCES request (id) MATCH SIMPLE 
     172                ON UPDATE CASCADE ON DELETE CASCADE 
     173            ) 
     174            }, 
     175            q{ 
     176            CREATE INDEX fki_request_id_fkey ON request_attributes 
     177            USING btree (reqid ) 
     178            }, 
     179            q{ 
     180            delete from accreq_attributes_list 
     181            } 
     182        ], 
     183    } 
    113184); 
    114185 
     
    155226while (my $row = $csv->getline($fh)) {  
    156227    my ($otype, $attribute, $comment) = @$row;  
    157     if ($labase->attribute($otype, $attribute)) {  
     228    if ($labase->is_registered_attribute($otype, $attribute)) {  
    158229    } else {  
    159230        $labase->register_attribute($otype, $attribute, $comment)  
Note: See TracChangeset for help on using the changeset viewer.