SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

/******所有的附件表添加domain******/
Declare @attachementTable varchar(500)
DECLARE listData CURSOR FOR  SELECT [name] FROM [pa_attachment_table]
OPEN listData
fetch next from listData INTO @attachementTable
WHILE @@FETCH_STATUS=0
Begin

IF Not EXISTS (select * from syscolumns where id=object_id(@attachementTable) and name='domain')
Begin
exec('ALTER TABLE ['+@attachementTable+'] ADD [domain] nvarchar(100)')
exec('update ['+@attachementTable+'] set domain=''''')
END

fetch next from listData INTO @attachementTable
END
CLOSE listData 
DEALLOCATE listData


/****** 添加pa_permission_information的CanSetSubmitState字段******/
IF Not EXISTS (select * from syscolumns where id=object_id('pa_permission_information') and name='canSetSubmitState')
Begin
ALTER TABLE [pa_permission_information] ADD [canSetSubmitState] smallint
execute('update [pa_permission_information] set [canSetSubmitState]=0')
END
GO


/****** 添加pa_field的uploadMaxWidth字段******/
IF Not EXISTS (select * from syscolumns where id=object_id('pa_field') and name='maxImageWidth')
Begin
ALTER TABLE [pa_field] ADD [maxImageWidth] smallint
execute('update [pa_field] set [maxImageWidth]=1920')
END
GO


/****** 添加pa_logining_user的nickName和avatar字段******/
IF Not EXISTS (select * from syscolumns where id=object_id('pa_logining_user') and name='nickName')
Begin
ALTER TABLE [pa_logining_user] ADD [avatar] nvarchar(150)
ALTER TABLE [pa_logining_user] ADD [nickName] nvarchar(50)
execute('update [pa_logining_user] set [nickName]=''''')
execute('update [pa_logining_user] set [avatar]=''''')
END
GO


/****** 管理菜单项添加字段******/
IF Not EXISTS (select * from syscolumns where id=object_id('pa_admin_menu_item') and name='remark')
Begin
ALTER TABLE [pa_admin_menu_item] ADD [category] nvarchar(50)
ALTER TABLE [pa_admin_menu_item] ADD [remark] nvarchar(250)
execute('update [pa_admin_menu_item] set [remark]='''',category=''''')
END
GO

/******会员菜单项添加字段******/
IF Not EXISTS (select * from syscolumns where id=object_id('pa_member_menu_item') and name='remark')
Begin
ALTER TABLE [pa_member_menu_item] ADD [category] nvarchar(50)
ALTER TABLE [pa_member_menu_item] ADD [remark] nvarchar(250)
execute('update [pa_member_menu_item] set [remark]='''',category=''''')
END
GO

/******管理菜单添加重启和切换的菜单项目******/

Declare @MenuId int
set @MenuId=0
IF not EXISTS (SELECT * FROM pa_admin_menu_item where action='RedirectToMemberCenter')
BEGIN
select @MenuId=[id] from pa_admin_menu where controller='Member'
if @MenuId>0
begin
insert into pa_admin_menu_item([menuId],[name],[namespace],[controller],[action],[method],[isDefault],[category],[remark]) values(@MenuId,'会员中心切换','PageAdmin.Web.Areas.Admin.Controllers','Member','RedirectToMemberCenter','GET',0,'','')
END
END

set @MenuId=0
IF not EXISTS (SELECT * FROM pa_admin_menu_item where action='Restart')
BEGIN
select @MenuId=[id] from pa_admin_menu where controller='SysSet'
if @MenuId>0
begin
insert into pa_admin_menu_item([menuId],[name],[namespace],[controller],[action],[method],[isDefault],[category],[remark]) values(@MenuId,'重启进程','PageAdmin.Web.Areas.Admin.Controllers','SysSet','Restart','POST',0,'','')
END
END

/******最后补充，下个版本继续加入******/
update pa_admin_menu set name='用户中心' where name='用户管理' and isFinal=0
update pa_admin_menu set name='用户管理' where name='会员管理' and isFinal=1
update pa_admin_menu set name='用户系统设置' where name='会员系统设置' and isFinal=1
update pa_admin_menu set name='用户组管理' where name='会员组管理' and isFinal=1
ALTER TABLE [dbo].[pa_column_seo_set] alter column [keywords] nvarchar(200)
delete from [pa_admin_menu] where [controller]='Site'
delete from [pa_admin_menu_item] where [controller]='Site'
GO

SET ANSI_PADDING OFF
GO
