
-----------------------------------------------------------------------------
-- TURBINE_PERMISSION
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_PERMISSION]
GO

CREATE TABLE [dbo].[TURBINE_PERMISSION](
    PERMISSION_ID INT 
       IDENTITY(1,1)
       CONSTRAINT PK_TURBINE_PERMISSION PRIMARY KEY NONCLUSTERED,
    PERMISSION_NAME VARCHAR(99) NOT NULL 
       UNIQUE,
    OBJECTDATA IMAGE
) ON [PRIMARY]
GO

-----------------------------------------------------------------------------
-- TURBINE_ROLE
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_ROLE]
GO

CREATE TABLE [dbo].[TURBINE_ROLE](
    ROLE_ID INT NOT NULL 
       IDENTITY(1,1)
       CONSTRAINT PK_TURBINE_ROLE PRIMARY KEY NONCLUSTERED,
    ROLE_NAME VARCHAR(99) NOT NULL
       UNIQUE,
    OBJECTDATA IMAGE
) ON [PRIMARY]
GO

-----------------------------------------------------------------------------
-- TURBINE_GROUP
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_GROUP]
GO

CREATE TABLE [dbo].[TURBINE_GROUP](
    GROUP_ID INT NOT NULL
       IDENTITY(1,1)
       CONSTRAINT PK_TURBINE_GROUP PRIMARY KEY NONCLUSTERED,
    GROUP_NAME VARCHAR(99) NOT NULL
       UNIQUE,
    OBJECTDATA IMAGE
) ON [PRIMARY]

-----------------------------------------------------------------------------
-- TURBINE_ROLE_PERMISSION
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_ROLE_PERMISSION]
GO

CREATE TABLE [dbo].[TURBINE_ROLE_PERMISSION](
    ROLE_ID INT NOT NULL,
    PERMISSION_ID INT NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TURBINE_ROLE_PERMISSION] WITH NOCHECK ADD 
	CONSTRAINT [PK_TURBINE_ROLE_PERMISSION] PRIMARY KEY  NONCLUSTERED 
	(
		[ROLE_ID],
		[PERMISSION_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TURBINE_ROLE_PERMISSION] ADD 
	CONSTRAINT [FK_trp_tr] FOREIGN KEY 
	(
		[ROLE_ID]
	) REFERENCES [dbo].[TURBINE_ROLE] (
		[ROLE_ID]
	),
	CONSTRAINT [FK_trp_tp] FOREIGN KEY 
	(
		[PERMISSION_ID]
	) REFERENCES [dbo].[TURBINE_PERMISSION] (
		[PERMISSION_ID]
	)
GO

-----------------------------------------------------------------------------
-- TURBINE_USER
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_USER]
GO

CREATE TABLE [dbo].[TURBINE_USER](
    USER_ID INT NOT NULL
       IDENTITY(1,1)
       CONSTRAINT PK_TURBINE_USER PRIMARY KEY NONCLUSTERED,
    LOGIN_NAME VARCHAR(32) NOT NULL
       CONSTRAINT UK_TURBINE_USER UNIQUE NONCLUSTERED,
    PASSWORD_VALUE VARCHAR(32) NOT NULL,
    FIRST_NAME VARCHAR(99) NOT NULL,
    LAST_NAME VARCHAR(99) NOT NULL,
    EMAIL VARCHAR(99),
    CONFIRM_VALUE VARCHAR(99),
    MODIFIED DATETIME,
    CREATED DATETIME,
    LASTLOGIN DATETIME,
    OBJECTDATA IMAGE
) ON [PRIMARY]
GO

-----------------------------------------------------------------------------
-- TURBINE_USER_GROUP_ROLE
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_USER_GROUP_ROLE]
GO

CREATE TABLE [dbo].[TURBINE_USER_GROUP_ROLE](
    USER_ID INT NOT NULL,
    GROUP_ID INT NOT NULL,
    ROLE_ID INT NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TURBINE_USER_GROUP_ROLE] WITH NOCHECK ADD 
	CONSTRAINT [PK_TURBINE_USER_GROUP_ROLE] PRIMARY KEY  NONCLUSTERED 
	(
		[USER_ID],
                [GROUP_ID],
		[ROLE_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TURBINE_USER_GROUP_ROLE] ADD 
	CONSTRAINT [FK_tugr_tu] FOREIGN KEY 
	(
		[USER_ID]
	) REFERENCES [dbo].[TURBINE_USER] (
		[USER_ID]
	),
	CONSTRAINT [FK_tugr_tg] FOREIGN KEY 
	(
		[GROUP_ID]
	) REFERENCES [dbo].[TURBINE_GROUP] (
		[GROUP_ID]
	)
GO

-----------------------------------------------------------------------------
-- TURBINE_SCHEDULED_JOB
-----------------------------------------------------------------------------
drop table [dbo].[TURBINE_SCHEDULED_JOB]
GO

CREATE TABLE [dbo].[TURBINE_SCHEDULED_JOB](
    JOB_ID INT NOT NULL
       IDENTITY(1,1)
       CONSTRAINT PK_TURBINE_SCHEDULED_JOB PRIMARY KEY NONCLUSTERED,
    SECOND INT default -1 NOT NULL,
    MINUTE INT default -1 NOT NULL,
    HOUR INT default -1 NOT NULL,
    WEEK_DAY INT default -1 NOT NULL,
    DAY_OF_MONTH INT default -1 NOT NULL,
    TASK VARCHAR(99) NOT NULL,
    EMAIL VARCHAR(99)
) ON [PRIMARY]
GO