﻿/*
 *
 * FtpServer建库/升级脚本
 * 作者：葛朋旭
 * 用途：提供给管理控制台进入FtpServer配置界面时调用
 * 调用条件：库中不存在Ftp所需表与字段
 * 
 */
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_BusiDoc')
Create Table T_FME_BusiDoc ( FID VARCHAR(44) NOT NULL ,FBusinessID VARCHAR(44) NOT NULL ,FDocumentID VARCHAR(44) NOT NULL ,FDisplayName NVARCHAR(512) NOT NULL ,CONSTRAINT PK_FME_BusiDoc PRIMARY KEY (FID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_Document')
Create Table T_FME_Document ( FDocumentID VARCHAR(44) NOT NULL ,FName NVARCHAR(80),FSize INT,FPath NVARCHAR(1000),FDescription NVARCHAR(255),FOperDate DateTime,FTypeID VARCHAR(44) NOT NULL ,FStatus CHAR(1),FServerID VARCHAR(44) NOT NULL ,CONSTRAINT PK_FME_Document PRIMARY KEY (FDocumentID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_FileCategory')
Create Table T_FME_FileCategory ( FID VARCHAR(44) NOT NULL ,FPID NVARCHAR(44),FName NVARCHAR(80),FDesc NVARCHAR(255),FStatus NVARCHAR(1),FPathID NVARCHAR(44),CONSTRAINT PK_FME_FleCategory PRIMARY KEY (FID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_FtpServer')
Create Table T_FME_FtpServer ( FServerID NVARCHAR(44) NOT NULL ,FServerName NVARCHAR(80),FServerHost NVARCHAR(80),FServerPort INT,FServerUser NVARCHAR(80),FServerPswd NVARCHAR(80),FRootPath NVARCHAR(80),FServerStatus NVARCHAR(1),FIsDefault INT,CONSTRAINT PK_FME_FtpServer PRIMARY KEY (FServerID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_OperLog')
Create Table T_FME_OperLog ( FID VARCHAR(44) NOT NULL ,FDocumentID VARCHAR(44) NOT NULL ,FOperType INT,FStaffID NVARCHAR(44),FOperDate DateTime,CONSTRAINT PK_FME_OperLog PRIMARY KEY (FID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_SavePath')
Create Table T_FME_SavePath ( FPathID VARCHAR(44) NOT NULL ,FPathName NVARCHAR(50),FDisplayName NVARCHAR(200),FServerID NVARCHAR(44),FPathStatus NVARCHAR(1),FSaveType INT,CONSTRAINT PK_FME_SavePath PRIMARY KEY (FPathID));
if not exists (select * from KSQL_USERTABLES where KSQL_TABNAME='T_FME_CategoryMap')
Create Table T_FME_CategoryMap ( FID VARCHAR(44) NOT NULL ,FBCID NVARCHAR(44),FFCID NVARCHAR(44),FMapName NVARCHAR(500),FLevel INT,CONSTRAINT PK_FME_CategoryMap PRIMARY KEY (FID));
if not exists (select * from KSQL_USERCOLUMNS where KSQL_COL_TABNAME='T_FME_FtpServer' and KSQL_COL_NAME='FIsDefault')
Alter table T_FME_FtpServer Add (FIsDefault INT);
IF NOT EXISTS (SELECT * FROM KSQL_USERCOLUMNS WHERE KSQL_COL_NAME = 'FAccessAddress' AND KSQL_COL_TABNAME = 'T_FME_FtpServer')
alter table T_FME_FtpServer  add FAccessAddress NVARCHAR(50);
IF NOT EXISTS (SELECT * FROM KSQL_USERCOLUMNS WHERE KSQL_COL_NAME = 'FInternetIP' AND KSQL_COL_TABNAME = 'T_FME_FtpServer')
alter table T_FME_FtpServer  add FInternetIP NVARCHAR(50);