PRINT N'Creating [dbo].[pal_LayoutType]...';

IF NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'pal_LayoutType')
BEGIN
CREATE TABLE [dbo].[pal_LayoutType] (
    [recId]  INT          IDENTITY (1, 1) NOT NULL,
    [layout] VARCHAR (50) NULL,
    CONSTRAINT [PK_pal_LayoutType] PRIMARY KEY CLUSTERED ([recId] ASC)
);
END

PRINT N'Creating [dbo].[pal_Promotion]...';

IF NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'pal_Promotion')
BEGIN
CREATE TABLE [dbo].[pal_Promotion] (
    [recId]        INT            IDENTITY (1, 1) NOT NULL,
    [title]        NVARCHAR (500) NULL,
    [caption]      NVARCHAR (MAX) NULL,
    [startDate]    DATETIME       NULL,
    [endDate]      DATETIME       NULL,
    [isActive]     BIT            NULL,
    [hideTitle]    BIT            NULL,
    [hideCaption]  BIT            NULL,
    [dateSaved]    DATETIME       NULL,
    [layoutTypeId] INT            NULL,
    [showOnHome]   BIT            NULL,
    CONSTRAINT [PK_pal_Advert] PRIMARY KEY CLUSTERED ([recId] ASC)
);
ALTER TABLE [dbo].[pal_Promotion]
    ADD CONSTRAINT [DF_pal_Advert_isActive] DEFAULT ((0)) FOR [isActive];
ALTER TABLE [dbo].[pal_Promotion]
    ADD CONSTRAINT [DF_pal_Advert_hideTitle] DEFAULT ((0)) FOR [hideTitle];
ALTER TABLE [dbo].[pal_Promotion]
    ADD CONSTRAINT [DF_pal_Advert_hideCaption] DEFAULT ((0)) FOR [hideCaption];
ALTER TABLE [dbo].[pal_Promotion]
    ADD CONSTRAINT [DF_pal_Advert_showOnHome] DEFAULT ((0)) FOR [showOnHome];
END

PRINT N'Creating [dbo].[pal_PromotionFile]...';

IF NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'pal_PromotionFile')
BEGIN
CREATE TABLE [dbo].[pal_PromotionFile] (
    [recId]       INT            IDENTITY (1, 1) NOT NULL,
    [promotionId] INT            NULL,
    [fileName]    NVARCHAR (500) NULL,
    [path]        NVARCHAR (MAX) NULL,
    [isActive]    BIT            NULL,
    CONSTRAINT [PK_pal_AdvertFile] PRIMARY KEY CLUSTERED ([recId] ASC)
);
ALTER TABLE [dbo].[pal_PromotionFile]
    ADD CONSTRAINT [DF_pal_AdvertFile_isActive] DEFAULT ((0)) FOR [isActive];

END

Truncate Table pal_LayoutType
SET IDENTITY_INSERT [dbo].[pal_LayoutType] ON
INSERT [dbo].[pal_LayoutType] ([recId], [layout]) VALUES (1, N'stack')
INSERT [dbo].[pal_LayoutType] ([recId], [layout]) VALUES (2, N'tile')
SET IDENTITY_INSERT [dbo].[pal_LayoutType] OFF

TRUNCATE TABLE pal_Module
SET IDENTITY_INSERT [dbo].[pal_Module] ON 
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (1, N'Content', 1, N'Admin_Content.aspx', N'module/content.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (3, N'Users', 3, N'Admin_Users.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, 1)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (4, N'Products', 4, N'Admin_Products.aspx', N'module/featuredProducts.ascx', 0, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (5, N'Product Categories', 5, N'Admin_ProductCategories.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (6, N'Product Brands', 6, N'Admin_ProductBrands.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (7, N'Banners', 7, N'Admin_Banners.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (8, N'Templates', 8, N'Admin_Templates.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (9, N'Gallery', 9, N'Admin_Gallery.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (10, N'Surface', 10, N'Admin_Surface.aspx', N'surface/surface.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (11, N'Canvas', 11, N'Admin_Canvas.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (12, N'Practices', 12, N'Debtors_Practices.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (13, N'Doctors', 13, N'Debtors_Doctors.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (14, N'Tariffs', 14, N'Debtors_Tariffs.aspx', N'debtors/tariffs.ascx', 1, 1, 1, N'oTariffPlan', N'name', N'code', NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (15, N'Procedures', 15, N'Debtors_Procedures.aspx', N'debtors/procedures.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (16, N'Medical Schemes', 16, N'Debtors_Schemes.aspx', N'debtors/schemes.ascx', 1, 1, 1, N'oMedicalScheme', N'name', N'code', NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (17, N'Notes', 17, N'', NULL, 0, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (18, N'Debtors Reports', 18, N'', N'module/debtorsReports.ascx', 0, 1, 0, N'', N'', N'', NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (19, N'Tasks', 19, N'Admin_Tasks.aspx', N'module/task.ascx', 1, 0, 0, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (20, N'FAQ', 20, N'Admin_FAQ.aspx', N'module/faq.ascx', 0, 1, 0, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (21, N'Medical Administrators', 21, N'Debtors_MedAdmins.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (22, N'Calendar', 22, N'Admin_Calendar.aspx', NULL, 0, 1, 0, NULL, NULL, NULL, 0)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (23, N'ICD10', 23, N'Debtors_ICD10.aspx', N'debtors/icd10.ascx', 1, 0, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (24, N'Enquiry', 24, N'', N'module/enquiry.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (25, N'Promotions', 25, N'Admin_Promotions.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[pal_Module] OFF


UPDATE	T
	SET	isActive = 1
--SELECT	*
FROM	pal_SurfaceFieldType T
WHERE	surfaceFieldType = 'Formula Field'
