--==============================================================
--  Database name:  XBRL TOOL SCHEMAS
--  DBMS name:      ORACLE Version 10g
--  Created on:     2007-05-16 XX:XX:XX
--  Description:    XBRL Report用のテーブルを作成します
--==============================================================

----------------------------------------------------------------
--- <テーブル名一覧>
---   xb_base_schema                基本スキーマテーブル
---   xb_item_type                  項目型テーブル
---   xb_taxonomy_group             タクソノミーグループテーブル
---   xb_taxonomy                   タクソノミーテーブル
---   xb_linkbaseref                参照リンクベーステーブル
---   xb_linkbase_arc               アークテーブル
---   xb_linkbase_locator           ロケータテーブル
---   xb_linkbase_resource          リンクベースリソーステーブル
---   xb_resource_item              リソースアイテムテーブル
---   xb_resource_item_attr         リソースアイテム属性テーブル
---   xb_taxonomy_item              タクソノミー科目テーブル
---   xb_item_label                 アイテムラベルテーブル
---   xb_item_work                  アイテムオーダーワークテーブル
---   xb_item_top                   アイテムルートテーブル
---   xb_item                       アイテムオーダーテーブル
---   xb_interface                  インターフェーステーブル
---   xb_item_interface             アイテムインターフェーステーブル
----------------------------------------------------------------

--------------------------------------------------
--- Taxonomy 系
--------------------------------------------------

--- <<基本スキーマテーブル>>
---   基本スキーマの名前空間及び識別子(名前空間URL)を管理する
create table xb_base_schema
(
  namespace             varchar(256) not null,
  namespace_url         varchar(512) not null,
  specification_no      varchar(3) not null,
  creation_date         timestamp not null,
  constraint  pk_xb_base_schema primary key (namespace, specification_no)
)
;

--- <<項目型テーブル>>
---   XBRLで使用する型の一覧を管理する
---   XBRLでは数値又は非数値どちらかの値で運用される
create table xb_item_type
(
  type_name             varchar(256) not null,
  attribute_name        varchar(15) not null,
  specification_no      varchar(3) not null,
  creation_date         timestamp not null,
  constraint  pk_xb_item_type primary key (type_name, specification_no)
)
;

--- <<タクソノミーグループテーブル>>
---   タクソノミーをグループ化する際の管理単位テーブル
create table xb_taxonomy_group
(
  taxonomy_group_id     bigint not null,
  taxonomy_group_name   varchar(32) not null,
  specification_no      varchar(3) not null,
  note                  varchar(256),
  creation_date         timestamp not null,
  constraint pk_xb_taxonomy_group primary key (taxonomy_group_id)
)
;

--- <<タクソノミーテーブル>>
---   タクソノミーファイルのitem(科目)以外の情報
create table xb_taxonomy
(
  taxonomy_id           bigint not null,
  taxonomy_group_id     bigint not null,
  taxonomy_name         varchar(128),
  taxonomy_file         varchar(128) not null,
  namespace             varchar(256) not null,
  namespace_url         varchar(512) not null,
  terminated_flag       smallint,
  creation_date         timestamp not null,
  constraint pk_xb_taxonomy primary key (taxonomy_id),
  constraint fk_xb_taxonomy foreign key (taxonomy_group_id)
    references xb_taxonomy_group (taxonomy_group_id)
)
;

--- <<参照リンクベーステーブル>>
---   linkbaseRefタグの情報を格納する
create table xb_linkbaseref
(
  linkbaseref_id        bigint not null,
  linkbase_role         varchar(128) not null,
  linkbase_href         varchar(256),
  taxonomy_id           bigint not null,
  taxonomy_group_id     bigint not null,
  category              varchar(64),
  creation_date         timestamp not null,
  constraint pk_xb_linkbaseref primary key (linkbaseref_id),
  constraint fk_xb_tax_linkbaseref foreign key (taxonomy_id)
    references xb_taxonomy (taxonomy_id),
  constraint fk_xb_tax_group_linkbaseref foreign key (taxonomy_group_id)
    references xb_taxonomy_group (taxonomy_group_id)
)
;

--- <<アークテーブル>>
---   各リンクベースのアーク情報を格納する
create table xb_linkbase_arc
(
  arc_id                        bigint not null,
  linkbaseref_id                bigint not null,
  arc_show                      varchar(10),
  arc_title                     varchar(512),
  arc_from                      varchar(256),
  arc_to                        varchar(256),
  arc_arcrole                   varchar(256),
  arc_use                       varchar(20),
  arc_priority                  bigint ,
  calculation_weight            numeric(10,4),
  presentation_order            numeric(10,4),
  constraint pk_xb_linkbase_arc primary key (arc_id),
  constraint fk_xb_arc_linkbase_ref foreign key (linkbaseref_id)
    references xb_linkbaseref (linkbaseref_id)
)
;

--- <<ロケータテーブル>>
---   各リンクベースのロケータ情報を格納する
create table xb_linkbase_locator
(
  locator_id                    bigint not null,
  linkbaseref_id                bigint not null,
  loc_href                      varchar(256) not null,
  loc_identifier                varchar(256) not null,
  loc_label                     varchar(256),
  loc_title                     varchar(512),
  loc_role                      varchar(256),
  constraint pk_xb_linkbase_loc primary key (locator_id),
  constraint fk_xb_loc_linkbase_ref foreign key (linkbaseref_id)
    references xb_linkbaseref (linkbaseref_id)
)
;

--- <<リソーステーブル>>
---   各リンクベースのリソース情報を格納する
---   ※主にラベルリンクとリファレンスリンクが該当する
create table xb_linkbase_resource
(
  resource_id                   bigint not null,
  linkbaseref_id                bigint not null,
  resource_label                varchar(256),
  resource_title                varchar(512),
  label_role                    varchar(256),
  label_lang                    varchar(8),
  resource_value                text,
  constraint pk_xb_linkbase_resource primary key (resource_id),
  constraint fk_xb_resource_linkbase_ref foreign key (linkbaseref_id)
    references xb_linkbaseref (linkbaseref_id)
)
;

--- <<リソースアイテムテーブル>>
---   リソースの値がタグ要素の場合、このテーブルに情報を格納する
create table xb_resource_item
(
  resource_item_id              bigint not null,
  resource_id                   bigint not null,
  namespace                     varchar(256),
  namespace_url                 varchar(512),
  item_name                     varchar(512),
  item_value                    text,
  constraint pk_xb_resource_item primary key (resource_item_id),
  constraint fk_xb_resource_item foreign key (resource_id)
    references xb_linkbase_resource (resource_id)
)
;

--- <<リソースアイテム属性テーブル>>
---   リソースの値がタグ要素の場合、このテーブルに情報を格納する(属性)
create table xb_resource_item_attr
(
  resource_item_attr_id         bigint not null,
  resource_item_id              bigint not null,
  attribute_name                varchar(512),
  attribute_value               varchar(512),
  constraint pk_xb_resource_item_attr primary key (resource_item_attr_id),
  constraint fk_xb_resource_item_attr foreign key (resource_item_id)
    references xb_resource_item (resource_item_id)
)
;

--- <<タクソノミー科目テーブル>>
---   XBRLの勘定科目群
create table xb_taxonomy_item
(
  taxonomy_item_id        bigint not null,
  taxonomy_id             bigint not null,
  taxonomy_group_id       bigint not null,
  item_id                 varchar(128),
  item_name               varchar(128),
  item_type               varchar(64),
  item_substitutiongroup  varchar(32),
  item_balance            varchar(10),
  item_nillable           smallint,
  item_period_type        varchar(10),
  abstract                smallint,
  documentation           text,
  creation_date           timestamp,
  constraint pk_xb_taxonomy_item primary key (taxonomy_item_id),
  constraint fk_item_taxonomy foreign key (taxonomy_id)
    references xb_taxonomy (taxonomy_id),
  constraint fk_item_taxonomy_group foreign key (taxonomy_group_id)
    references xb_taxonomy_group (taxonomy_group_id)
)
;

--- <<アイテムラベルテーブル>>
--- アイテムのラベル名を格納する
create table xb_item_label
(
    taxonomy_group_id              bigint not null,
    taxonomy_id                    bigint not null,
    taxonomy_item_id               bigint not null,
    label_lang                     varchar(8),
    resource_value                 text
)
;

--- <<アイテムオーダーワークテーブル>>
--- アイテムの親子関係と並び順を格納するワークテーブル
create table xb_item_work
(
    taxonomy_group_id              bigint not null,
    taxonomy_id                    bigint not null,
    taxonomy_item_id               bigint not null,
    item_type                      varchar(32),
    parent_taxonomy_item_id        bigint not null,
    parent_item_type               varchar(32),
    context_type                   varchar(32),
    presentation_order             numeric(10,4)
)
;

--- <<アイテムルートテーブル>>
--- アイテムのｔｏｐを格納する
create table xb_item_top
(
    taxonomy_group_id              bigint not null,
    taxonomy_item_id               bigint not null,
    item_lang                      varchar(8),
    item_name                      text
)
;

--- <<アイテムオーダーテーブル>>
--- アイテムの親子関係と並び順を格納する
create table xb_item
(
    item_order                     int not null,
    taxonomy_group_id              bigint not null,
    taxonomy_id                    bigint not null,
    taxonomy_item_id               bigint not null,
    item_type                      varchar(32),
    parent_taxonomy_item_id        bigint not null,
    parent_item_type               varchar(32),
    context_type                   varchar(32),
    presentation_order             numeric(10,4),
    item_lang                      varchar(8),
    item_name                      text,
    constraint pk_xb_item primary key (item_order, taxonomy_group_id, taxonomy_item_id, item_lang)
)
;

--- <<インターフェーステーブル>>
--- アイテムを格納する
create table xb_interface
(
    item_order                     int not null,
    taxonomy_item_id               bigint not null,
    taxonomy_item_seq              int not null,
    parent_taxonomy_item_id        bigint not null,
    parent_taxonomy_item_seq       int not null,
    item_value                     varchar(512),
    item_precision                 int,
    item_decimal                   int,
    context_type                   varchar(32),
    context_name                   varchar(128),
    unit_name                      varchar(128),
    footnote_value                 varchar(128)
)
;

--- <<アイテムインターフェーステーブル>>
--- ユーザーアイテムを格納する
create table xb_item_interface
(
    user_item_id                   bigint not null,
    item_value                     varchar(512),
    entity                         varchar(128),
    period                         varchar(10),
    unit                           varchar(128)
)
;
create table xb_context
(
    context_id                     bigint not null,
    context_type                   varchar(32) not null,
    context_name                   varchar(128) not null,
    name                           varchar(128) not null,
    entity_id                      bigint not null,
    fiscal_year                    int,
    period_start_date              varchar(10),
    period_end_date                varchar(10),
    item_precision                 int not null,
    item_cwa                       int not null,
    unit_flag                      smallint not null,
    description                    varchar(512),
    creation_date                  timestamp not null
)
create unique index pk_xb_context on xb_context
(context_id)
;
create table xb_context_unit
(
    context_id                     bigint not null,
    unit_id                        bigint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_context_unit on xb_context_unit
(context_id, unit_id)
;
create table xb_unit
(
    unit_id                        bigint not null,
    unit_name                      varchar(128) not null,
    name                           varchar(128),
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_unit on xb_unit
(unit_id)
;
create table xb_unit_measure
(
    unit_id                        bigint not null,
    measure_id                     bigint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_unit_measure on xb_unit_measure
(unit_id, measure_id)
;
create table xb_unit_divide
(
    unit_id                        bigint not null,
    divide_id                      bigint not null,
    operator_type                  smallint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_unit_divide on xb_unit_divide
(unit_id, divide_id)

create table xb_divide_measure
(
    divide_id                      bigint not null,
    divide_type                    smallint not null,
    measure_id                     bigint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_divide_measure on xb_divide_measure
(divide_id, divide_type, measure_id)
;
create table xb_measure
(
    measure_id                     bigint not null,
    measure_name                   varchar(128) not null,
    money_flag                     smallint not null,
    value                          varchar(128) not null,
    creation_date                  timestamp not null
)
create unique index pk_xb_measure on xb_measure
(measure_id)
;
create table xb_context_scenario
(
    main_id                        bigint not null,
    etc_type                       smallint not null,
    etc_id                         bigint not null,
    parent_etc_id                  bigint not null,
    prefix                         varchar(128),
    uri                            varchar(512),
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_context_scenario on xb_context_scenario
(main_id, etc_type, etc_id, parent_etc_id, prefix)
;
create table xb_entity
(
    entity_id                      bigint not null,
    entity_name                    varchar(128) not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_entity on xb_entity
(entity_id)

create table xb_entity_identifier
(
    entity_id                      bigint not null,
    identifier_id                  bigint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_entity_identifier on xb_entity_identifier
(entity_id, identifier_id)
;
create table xb_entity_segment
(
    main_id                        bigint not null,
    etc_type                       smallint not null,
    etc_id                         bigint not null,
    parent_etc_id                  bigint not null,
    prefix                         varchar(128),
    uri                            varchar(512),
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_entity_segment on xb_entity_segment
(main_id, etc_type, etc_id, parent_etc_id, prefix)

create table xb_identifier
(
    identifier_id                  bigint not null,
    identifier_name                varchar(128) not null,
    schema                         varchar(512),
    value                          varchar(128) not null,
    creation_date                  timestamp not null
)
create unique index pk_xb_identifier on xb_identifier
(identifier_id)
;
create table xb_etc
(
    etc_type                       smallint not null,
    etc_id                         bigint not null,
    etc_name                       varchar(128) not null,
    name                           varchar(128),
    value                          text,
    creation_date                  timestamp not null
)
create unique index pk_xb_etc on xb_etc
(etc_type, etc_id)

create table xb_etc_attributes
(
    etc_type                       smallint not null,
    etc_id                         bigint not null,
    name                           varchar(128) not null,
    value                          varchar(128) not null,
    creation_date                  timestamp not null
)
create unique index pk_xb_etc_attributes on xb_etc_attributes
(etc_type, etc_id, name)

create table xb_ref
(
    ref_type                       smallint not null,
    ref_id                         bigint not null,
    ref_name                       varchar(128) not null,
    creation_date                  timestamp not null
)
create unique index pk_xb_ref on xb_ref
(ref_type, ref_id)
;
create table xb_ref_attributes
(
    ref_type                       smallint not null,
    ref_id                         bigint not null,
    name                           varchar(128) not null,
    value                          varchar(512) not null,
    creation_date                  timestamp not null
)
create unique index pk_xb_ref_attributes on xb_ref_attributes
(ref_type, ref_id, name)
;
create table xb_mapping
(
    taxonomy_group_id              bigint not null,
    taxonomy_item_id               bigint not null,
    user_item_id                   bigint not null,
    item_precision                 int,
    item_decimal                   int,
    etc_type                       smallint,
    etc_id                         bigint,
    tuple_child_flag               smallint not null,
    description                    varchar(512),
    creation_date                  timestamp not null
)
create unique index pk_xb_mapping on xb_mapping
(taxonomy_group_id, taxonomy_item_id)
;
create table xb_tuple_data
(
    item_order                     bigint not null,
    taxonomy_group_id              bigint not null,
    taxonomy_item_id               bigint not null,
    taxonomy_item_seq              bigint not null,
    parent_taxonomy_item_id        bigint not null,
    parent_taxonomy_item_seq       bigint not null,
    item_value                     varchar(512),
    context_id                     bigint not null
)
;
create table xb_item_footnote
(
    main_id                        bigint not null,
    etc_type                       smallint not null,
    etc_id                         bigint not null,
    parent_etc_id                  bigint not null,
    presentation_order             bigint,
    creation_date                  timestamp not null
)
create unique index pk_xb_item_footnote on xb_item_footnote
(main_id, etc_type, etc_id, parent_etc_id)
;