- Timestamp:
- 04/01/15 18:41:35 (9 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/bin/la-sql-upgrade.in
r1225 r1308 202 202 ALTER TABLE revaliases ADD COLUMN description text; 203 203 }, 204 ],205 },206 {207 ver => 7,208 sql => [209 204 q{ 210 205 CREATE OR REPLACE FUNCTION group_sort_fields() … … 259 254 ], 260 255 }, 261 256 { 257 ver => 8, 258 sql => [ 259 q{ 260 CREATE TABLE objectslogs 261 ( 262 logkey SERIAL NOT NULL, 263 ikey bigint NOT NULL, 264 otype text NOT NULL, 265 name text NOT NULL, 266 changetype text NOT NULL, 267 username text NOT NULL, 268 message text NOT NULL, 269 logdate timestamp with time zone NOT NULL DEFAULT now(), 270 CONSTRAINT objectlogs_pkey PRIMARY KEY (logkey) 271 );}, 272 q{ 273 CREATE INDEX objectlogs_name_idx 274 ON objectslogs 275 USING btree 276 (name); 277 }, 278 q{ 279 CREATE INDEX objectslogs_ikey_idx 280 ON objectslogs 281 USING btree 282 (ikey); 283 }, 284 q{ 285 CREATE INDEX objectslogs_otype_idx 286 ON objectslogs 287 USING btree 288 (otype); 289 } 290 ], 291 }, 292 { 293 ver => 9, 294 sql => [ 295 q{ 296 CREATE TABLE nethost_attributes_nethosts 297 ( 298 CONSTRAINT nethost_attributes_nethosts_pkey PRIMARY KEY (attr_key), 299 CONSTRAINT nethost_attr_nethosts_fkey FOREIGN KEY (okey) 300 REFERENCES nethost (ikey) MATCH SIMPLE 301 ON UPDATE CASCADE ON DELETE CASCADE, 302 CONSTRAINT nethost_attr_nethosts_nethosts FOREIGN KEY ("value") 303 REFERENCES nethost (name) MATCH SIMPLE 304 ON UPDATE CASCADE ON DELETE CASCADE 305 ) 306 INHERITS (nethost_attributes); 307 308 CREATE INDEX fki_nethost_attr_nethosts_fkey 309 ON nethost_attributes_nethosts 310 USING btree 311 (okey); 312 313 CREATE TRIGGER nethost_attr_nethosts_update 314 AFTER INSERT OR UPDATE OR DELETE 315 ON nethost_attributes_nethosts 316 FOR EACH ROW 317 EXECUTE PROCEDURE nethost_attr_update_ref(); 318 319 320 CREATE OR REPLACE FUNCTION nethost_sort_fields() 321 RETURNS trigger AS 322 $BODY$BEGIN 323 324 IF (TG_OP='INSERT') then 325 IF (new.attr='ip') THEN 326 insert into nethost_attributes_ips VALUES (new.*); 327 RETURN NULL; 328 END IF; 329 330 IF (new.attr='macaddr') THEN 331 insert into nethost_attributes_macs VALUES (new.*); 332 RETURN NULL; 333 END IF; 334 335 IF (new.attr='owner') THEN 336 insert into nethost_attributes_users VALUES (new.*); 337 RETURN NULL; 338 END IF; 339 340 IF (new.attr='user') THEN 341 insert into nethost_attributes_users VALUES (new.*); 342 RETURN NULL; 343 END IF; 344 345 IF (new.attr='related') THEN 346 insert into nethost_attributes_nethosts VALUES (new.*); 347 RETURN NULL; 348 END IF; 349 end if; 350 351 if (TG_OP='DELETE') THEN 352 RETURN old; 353 else 354 RETURN new; 355 end if; 356 END;$BODY$ 357 LANGUAGE plpgsql VOLATILE 358 COST 100; 359 360 } 361 ], 362 }, 363 { 364 ver => 10, 365 sql => [ 366 q{ 367 CREATE OR REPLACE FUNCTION service_attr_update_ref() 368 RETURNS trigger AS 369 $BODY$begin 370 371 IF (TG_OP != 'INSERT') then 372 update "service" set date = now() where "service".ikey = old.okey; 373 end if; 374 IF (TG_OP != 'DELETE') then 375 update "service" set date = now() where "service".ikey = new.okey; 376 end if; 377 378 IF (TG_OP = 'DELETE') then 379 return old; 380 ELSE 381 return new; 382 END IF; 383 384 END;$BODY$ 385 LANGUAGE plpgsql VOLATILE 386 COST 100; 387 }, 388 q{ 389 390 CREATE TABLE service 391 ( 392 393 CONSTRAINT service_pkey PRIMARY KEY (name), 394 CONSTRAINT service_ikey_uniq UNIQUE (ikey) 395 ) 396 INHERITS (objects); 397 }, 398 q{ 399 400 CREATE TABLE service_attributes_list 401 ( 402 ikey integer NOT NULL DEFAULT nextval('ikey_seq'::regclass), 403 canonical text NOT NULL, 404 description text, 405 CONSTRAINT service_attributes_list_pkey PRIMARY KEY (ikey), 406 CONSTRAINT g_attr_l_service_uniq UNIQUE (canonical) 407 ) 408 INHERITS (revisions, attributes_list) 409 WITH ( 410 OIDS=FALSE 411 ); 412 ALTER TABLE service_attributes_list 413 OWNER TO latmos; 414 415 CREATE TABLE service_attributes 416 ( 417 CONSTRAINT service_attributes_pkey PRIMARY KEY (attr_key), 418 CONSTRAINT service_attr_users_okey_fkey FOREIGN KEY (okey) 419 REFERENCES service (ikey) MATCH SIMPLE 420 ON UPDATE CASCADE ON DELETE CASCADE, 421 CONSTRAINT service_attributes_attr_fkey FOREIGN KEY (attr) 422 REFERENCES service_attributes_list (canonical) MATCH SIMPLE 423 ON UPDATE CASCADE ON DELETE NO ACTION 424 ) 425 INHERITS (attributes) 426 WITH ( 427 OIDS=FALSE 428 ); 429 ALTER TABLE service_attributes 430 OWNER TO latmos; 431 432 CREATE INDEX fki_service_attributes_attr_fkey 433 ON nethost_attributes 434 USING btree 435 (attr); 436 437 CREATE INDEX service_attr_value_idx 438 ON nethost_attributes 439 USING btree 440 (value); 441 442 CREATE TRIGGER serivce_attr_update 443 AFTER INSERT OR UPDATE OR DELETE 444 ON service_attributes 445 FOR EACH ROW 446 EXECUTE PROCEDURE service_attr_update_ref(); 447 }, 448 q{ 449 CREATE TABLE service_attributes_users 450 ( 451 CONSTRAINT service_attributes_user_pkey PRIMARY KEY (attr_key), 452 CONSTRAINT service_attr_users_okey_fkey FOREIGN KEY (okey) 453 REFERENCES service (ikey) MATCH SIMPLE 454 ON UPDATE CASCADE ON DELETE CASCADE, 455 CONSTRAINT service_attributes_users_attr_fkey FOREIGN KEY (attr) 456 REFERENCES service_attributes_list (canonical) MATCH SIMPLE 457 ON UPDATE CASCADE ON DELETE NO ACTION, 458 CONSTRAINT service_attributes_users_user_fkey FOREIGN KEY (value) 459 REFERENCES "user" (name) MATCH SIMPLE 460 ON UPDATE CASCADE ON DELETE CASCADE, 461 CONSTRAINT service_attributes_users_uniq UNIQUE (okey, attr, value) 462 ) 463 INHERITS (service_attributes); 464 465 CREATE INDEX fki_service_attr_users_okey_fkey 466 ON service_attributes_users 467 USING btree 468 (okey); 469 470 CREATE INDEX fki_service_attributes_users_attr_fkey 471 ON service_attributes_users 472 USING btree 473 (attr); 474 475 CREATE INDEX fki_service_attributes_users_user_fkey 476 ON service_attributes_users 477 USING btree 478 (value); 479 480 CREATE TRIGGER service_attributes_users_update_ref 481 AFTER INSERT OR UPDATE OR DELETE 482 ON service_attributes_users 483 FOR EACH ROW 484 EXECUTE PROCEDURE service_attr_update_ref(); 485 486 CREATE OR REPLACE FUNCTION service_sort_fields() 487 RETURNS trigger AS 488 $BODY$BEGIN 489 490 if (TG_OP='INSERT' or TG_OP='UPDATE') THEN 491 IF (new.attr='manager') THEN 492 insert into service_attributes_users VALUES (new.*); 493 RETURN NULL; 494 END IF; 495 END IF; 496 497 if (TG_OP='DELETE') THEN 498 RETURN old; 499 else 500 RETURN new; 501 end if; 502 END;$BODY$ 503 LANGUAGE plpgsql VOLATILE 504 COST 100; 505 506 CREATE TRIGGER service_sort_field_tg 507 BEFORE INSERT OR UPDATE OR DELETE 508 ON service_attributes 509 FOR EACH ROW 510 EXECUTE PROCEDURE service_sort_fields(); 511 512 }, 513 ], 514 }, 262 515 ); 263 516 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r1303 r1308 103 103 $info->{exported} = { inline => 1, formtype => 'CHECKBOX', hide => 1, monitored => 1 }; 104 104 $info->{unexported} = { inline => 1, formtype => 'CHECKBOX', }; 105 $info->{services} = { inline => 1, ro => 1,};105 $info->{services} = { inline => 1, multiple => 1, reference => 'service' }; 106 106 107 107 $info … … 320 320 if (exists($data{exported})) { 321 321 $data{exported} ||= 0; 322 } 323 if (exists($data{services})) { 324 my %old = map { $_ => 0 } $self->get_attributes('services'); 325 foreach my $serv (grep { $_ } ref $data{services} ? @{ $data{services} } : $data{services}) { 326 if (!exists($old{$serv})) { 327 my $oserv = $self->base->get_object('service', $serv) or next; 328 $oserv->addAttributeValue('dependOn', $self->type . '.' . $self->id); 329 } 330 $old{$serv} = 1; 331 } 332 foreach my $serv (keys %old) { 333 if (!$old{$serv}) { 334 my $oserv = $self->base->get_object('service', $serv) or next; 335 $oserv->delAttributeValue('dependOn', $self->type . '.' . $self->id); 336 } 337 } 338 delete($data{services}); 322 339 } 323 340 foreach my $field (keys %data) {
Note: See TracChangeset
for help on using the changeset viewer.