---  ~ Licensed to the Apache Software Foundation (ASF) under one
---  ~ or more contributor license agreements.  See the NOTICE file
---  ~ distributed with this work for additional information
---  ~ regarding copyright ownership.  The ASF licenses this file
---  ~ to you under the Apache License, Version 2.0 (the
---  ~ "License"); you may not use this file except in
---  ~ compliance with the License.  You may obtain a copy of the License at
---  ~
---  ~    http://www.apache.org/licenses/LICENSE-2.0
---  ~
---  ~ Unless required by applicable law or agreed to in writing,
---  ~ software distributed under the License is distributed on an
---  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
---  ~ KIND, either express or implied.  See the License for the
---  ~ specific language governing permissions and limitations
---  ~ under the License.

create table gadget
(
    gadget_id           number(38)     not null,
    title               varchar2(100)  not null,
    description         varchar2(4000) not null,
    gadget_author_type_id number(38)    not null,
    author              varchar2(100)  not null,
    author_user_id     varchar2(20),
    gadget_support_link_type_id number(38) not null,
    support_link         varchar2(100),
    url	                varchar2(200)  not null,
    thumbnail_url       varchar2(200),
    screenshot_url      varchar2(200),
    use_custom_edit_ui  varchar2(1)    not null,    
    version             varchar2(10)   not null,
    featured            varchar2(1)    not null,
    scrolling            varchar2(1)    not null,         
    height               number(5),
    created_date        date           not null,
    created_by          varchar2(50)   not null,
    modified_date       date           not null,
    modified_by         varchar2(50)   not null,
    hidden            varchar2(1)    not null,
    send_comment_emails   varchar2(1)    not null,
    constraint  gadget_pk 
        primary key (gadget_id),
    constraint  gadget_url_unq 
        unique (url),
    constraint gadget_use_custom_edit_ui_chk
        check (use_custom_edit_ui in ('Y','N')),
    constraint gadget_featured_chk
        check (featured in ('Y','N')),
    constraint gadget_scrolling_chk
        check (scrolling in ('Y','N')),
    constraint gadget_hidden_chk
        check (hidden in ('Y','N')),                
    constraint gadget_send_comment_chk
        check (send_comment_emails in ('Y','N'))                                   
);

ALTER TABLE GADGET
ADD CONSTRAINT GADGET_AUTHOR_TYPE_FK 
FOREIGN KEY (GADGET_AUTHOR_TYPE_ID)
REFERENCES GADGET_AUTHOR_TYPE (GADGET_AUTHOR_TYPE_ID);

ALTER TABLE GADGET
ADD CONSTRAINT GADGET_SUPPORT_LINK_TYPE_FK 
FOREIGN KEY (GADGET_SUPPORT_LINK_TYPE_ID)
REFERENCES GADGET_SUPPORT_LINK_TYPE (GADGET_SUPPORT_LINK_TYPE_ID);

