This is the ddl for my database.

CREATE OR REPLACE FUNCTION manage_object() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
object_entity_name TEXT;
begin
IF (TG_OP = 'INSERT') THEN
IF NEW.id IS NULL THEN
insert into object (entity_name) values (TG_RELNAME) RETURNING id INTO 
NEW.id;
ELSE
select entity_name into object_entity_name from object where id=NEW.id;
IF FOUND THEN
IF EXISTS (select * from information_schema.tables where 
table_catalog=CURRENT_CATALOG and table_schema=CURRENT_SCHEMA and 
table_name=object_entity_name) THEN
EXECUTE 'select * from '
|| object_entity_name 
|| ' where id=$1' USING NEW.id;
IF FOUND THEN
RAISE EXCEPTION 'The object id is alreasy assigned to another object.';

END If;
ELSE
IF (object_entity_name != TG_RELNAME) THEN
update object set entity_name=TG_RELNAME where id=NEW.id;
END IF;
END IF;
ELSE
insert into object (id, entity_name) values (NEW.id, TG_RELNAME);
END IF;
END IF;
RETURN NEW;
ELSIF (TG_OP = 'UPDATE') THEN
update object set id=NEW.id, entity_name=TG_RELNAME where id=OLD.id;
return NEW;
ELSIF (TG_OP = 'DELETE') THEN
delete from object where id=OLD.id;
return OLD;
END IF;
end;
$$;

CREATE OR REPLACE FUNCTION manage_actor() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
actor_entity_name TEXT;
begin
IF (TG_OP = 'INSERT') THEN
IF NEW.id IS NULL THEN
insert into actor (entity_name) values (TG_RELNAME) RETURNING id INTO 
NEW.id;
ELSE
select entity_name into actor_entity_name from actor where id=NEW.id;
IF FOUND THEN
IF EXISTS (select * from information_schema.tables where 
table_catalog=CURRENT_CATALOG and table_schema=CURRENT_SCHEMA and 
table_name=actor_entity_name) THEN
EXECUTE 'select * from '
|| actor_entity_name 
|| ' where id=$1' USING NEW.id;
IF FOUND THEN
RAISE EXCEPTION 'The actor id is alreasy assigned to another actor.';

END If;
ELSE
IF (actor_entity_name != TG_RELNAME) THEN
update actor set entity_name=TG_RELNAME where id=NEW.id;
END IF;
END IF;
ELSE
insert into actor (id, entity_name) values (NEW.id, TG_RELNAME);
END IF;
END IF;
RETURN NEW;
ELSIF (TG_OP = 'UPDATE') THEN
update actor set id=NEW.id, entity_name=TG_RELNAME where id=OLD.id;
return NEW;
ELSIF (TG_OP = 'DELETE') THEN
delete from actor where id=OLD.id;
return OLD;
END IF;
end;
$$;

CREATE TABLE module (
name varchar(100),
title varchar(255) NOT NULL,
description varchar(255) NOT NULL,
status smallint not null,
PRIMARY KEY (name)
);

CREATE TABLE object (
id serial,
entity_name varchar(255) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE actor (
id serial,
entity_name varchar(255) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE email_address (
email_address varchar(50) NOT NULL,
actor_id integer NOT NULL,
status smallint NOT NULL,
create_time timestamp NOT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (email_address)
);

alter table email_address
add constraint fk_email_address_actor foreign key (actor_id) references 
actor(id) on delete cascade on update cascade;

CREATE TABLE email_address_confirmation (
email_address varchar(50) NOT NULL,
code varchar(32) NOT NULL,
create_time timestamp NOT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (email_address)
);

alter table email_address_confirmation
add constraint fk_email_address_confirmation_email_address foreign key 
(email_address) references email_address(email_address) on delete cascade on 
update cascade;

CREATE TABLE person (
id integer not null,
email_address varchar(50) NOT NULL,
username varchar(32) DEFAULT NULL,
password varchar(32) NOT NULL,
status smallint NOT NULL,
create_ip varchar(39) NOT NULL,
create_time timestamp NOT NULL,
update_time timestamp DEFAULT NULL,
UNIQUE (email_address),
UNIQUE (username),
PRIMARY KEY (id)
);

alter table person
add constraint fk_actor foreign key (id) references actor(id) on delete 
cascade on update cascade;


create table person_profile (
person_id integer not null,
primary key(person_id)
);

alter table person_profile
add constraint fk_person_profile_person foreign key (person_id) references 
person(id) on delete cascade on update cascade;

CREATE TRIGGER manage_person BEFORE INSERT OR UPDATE OR DELETE ON person FOR 
EACH ROW EXECUTE PROCEDURE manage_actor();

CREATE TABLE person_password_reset (
person_id integer NOT NULL,
code varchar(32) NOT NULL,
create_time timestamp NOT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (person_id)
);

alter table person_password_reset
add constraint fk_person_password_reset_person foreign key (person_id) 
references person(id) on delete cascade on update cascade;

CREATE TABLE contact_group (
id serial,
person_id integer NOT NULL,
name varchar(255) not null,
create_time timestamp NOT NULL,
update_time timestamp default NULL,
PRIMARY KEY (id),
UNIQUE (person_id,name)
);

alter table contact_group
add constraint fk_contact_group_person foreign key (person_id) references 
person(id) on delete cascade on update cascade;

CREATE TABLE contact (
id serial,
person_id integer NOT NULL,
person2_id integer NOT NULL,
status smallint not null,
create_time timestamp NOT NULL,
PRIMARY KEY (id),
UNIQUE (person_id,person2_id)
);

alter table contact
add constraint fk_contact_person foreign key (person_id) references 
person(id) on delete cascade on update cascade,
add constraint fk_contact_person2 foreign key (person2_id) references 
person(id) on delete cascade on update cascade;

CREATE TABLE contact_group_contact (
contact_group_id integer NOT NULL,
contact_id integer not null,
PRIMARY KEY (contact_group_id, contact_id)
);

alter table contact_group_contact
add constraint fk_contact_group_contact_contact foreign key (contact_id) 
references contact(id) on delete cascade on update cascade,
add constraint fk_contact_group_contact_contact_group foreign key 
(contact_group_id) references contact_group(id) on delete cascade on update 
cascade;

I am using postgresql 9.0.3

Generating entities works on a simpler database structure i tested it with, 
but for some reason, it chokes with this 1.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to