--
-- f_attributedefinition
--
DROP TABLE IF EXISTS f_attributedefinition;

create table f_attributedefinition (
    tablename         varchar(64) not null,
    classid           integer not null,
    columnname        varchar(255) not null,
    attributename     varchar(4000) not null,
    idposition        smallint,
    columntype        varchar(30) not null,
    columnsize        bigint not null,
    columnscale       smallint,
    attributetype     varchar(512) not null,
    geometrytype      varchar(64),
    isnullable        smallint not null,
    isfeatid          smallint not null,
    issystem          smallint not null,
    isreadonly        smallint not null,
    isautogenerated   smallint,
    isrevisionnumber  smallint,
    sequencename      varchar(30),
    owner             varchar(255),
    description       varchar(255),
    rootobjectname    varchar(64),
    isfixedcolumn     smallint,
    iscolumncreator   smallint,
    haselevation      smallint,
    hasmeasure        smallint
);

COMMENT ON TABLE f_attributedefinition IS 'Definition of properties for classes from FDO feature schema.';

-- Base properties common to all classes

insert into f_classdefinition 
(classname, schemaname, tablename,classtype, description, isabstract, parentclassname, istablecreator, isfixedtable, hasversion, haslock)
values
('ClassDefinition', 'F_MetaClass', 'f_classdefinition', 1, 'Base for all metaclasses', 1, null, 0, 1, 0, 0); 

insert into f_attributedefinition
(tablename, classid, columnname, attributename, columntype, columnsize, columnscale, attributetype, isnullable, 
isfeatid, issystem, isreadonly, isautogenerated, isrevisionnumber, owner, description, iscolumncreator, isfixedcolumn)
values
('f_classdefinition', currval('f_classdefinition_classid_seq'), 'classname', 'ClassName', 'CHAR', 30, 0, 'string', 0, 0, 1, 1, 0, 0,
current_user, 'FDO base property: object class name', 0, 1);

insert into f_attributedefinition
(tablename, classid, columnname, attributename, columntype, columnsize, columnscale, attributetype, isnullable, 
isfeatid, issystem, isreadonly, isautogenerated, isrevisionnumber, owner, description, iscolumncreator, isfixedcolumn)
values
('f_classdefinition', currval('f_classdefinition_classid_seq'), 'schemaname', 'SchemaName', 'CHAR', 255, 0, 'string', 1, 0, 1, 1, 0, 0,
current_user, 'FDO base property: object class schema name', 0, 1);

insert into f_attributedefinition
(tablename, classid, columnname, attributename, idposition, columntype, columnsize, columnscale, attributetype, 
isnullable, isfeatid, issystem, isreadonly, isautogenerated, isrevisionnumber, owner, description, iscolumncreator, isfixedcolumn)
values
('f_feature', currval('f_classdefinition_classid_seq'), 'classid', 'ClassId', 1, 'BIGINT', 0, 0, 'int64', 0, 0, 1, 1, 1, 0,
current_user, 'Class id number (uniquely identifies a class)', 0, 1);

insert into f_attributedefinition
(tablename, classid, columnname, attributename, columntype, columnsize, columnscale, attributetype, geometrytype, isnullable, 
isfeatid, issystem, isreadonly, isautogenerated, isrevisionnumber, owner, description, iscolumncreator, isfixedcolumn)
values
('n/a', currval('f_classdefinition_classid_seq'), 'n/a', 'Bounds', 'GEOMETRY', 0, 0, '4', '84224', 1, 0, 1, 1, 0, 0,
current_user, 'Bounding box for the feature', 0, 0);