Beispiel #1
0
        protected void InitDb()
        {
            Db.Connection.Execute($"IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = '{_dbName}') CREATE DATABASE [{_dbName}];");
            Db.Connection.Execute($"USE [{_dbName}]");

            ClearDb();

            void CreateSchema(string dbSchema)
            {
                Db.Connection.Execute($@"IF schema_id('{dbSchema}') IS NULL EXECUTE('CREATE SCHEMA {dbSchema}') ");
            }

            CreateSchema("DAB");

            Db.Connection.Execute(
                @"CREATE TABLE Users (Id int IDENTITY(1,1) not null, Name varchar(256) not null, AddressId int not null, PhoneId int not null, OfficePhoneId int not null, Deleted bit not null, UpdatedAt datetime2, PRIMARY KEY (Id))");
            Db.Connection.Execute(
                @"CREATE TABLE Cars (Id int IDENTITY(1,1) not null, Name varchar(256) not null, UserId int not null, Status int not null, Data binary(16) null, PRIMARY KEY (Id))");

            Db.Connection.Execute(@"CREATE TABLE Addresses (Id int IDENTITY(1,1) not null, Street varchar(256) not null, CityId varchar(256) not null,  PRIMARY KEY (Id))");
            Db.Connection.Execute(@"CREATE TABLE Cities (Identifier uniqueidentifier not null, Name varchar(256) not null)");
            Db.Connection.Execute(@"CREATE TABLE Reports (Id int not null, AnotherId int not null, UserId int not null,  PRIMARY KEY (Id, AnotherId))");
            Db.Connection.Execute(
                @"CREATE TABLE DAB.Phones (Id int IDENTITY(1,1) not null, Number varchar(256) not null, IsActive bit not null, Code varchar(256) not null, PRIMARY KEY (Id))");

            InitData.Execute(Db);
        }
Beispiel #2
0
        private void InitDb()
        {
            SetupSchema();
            Db.Connection.Execute(
                @"CREATE TABLE USERS (
                  ID NUMBER GENERATED ALWAYS AS IDENTITY(START WITH 1 INCREMENT BY 1),
                  NAME VARCHAR(256) NOT NULL, 
                  ADDRESSID NUMBER NOT NULL, 
                  PHONEID NUMBER NOT NULL, 
                  OFFICEPHONEID NUMBER NOT NULL, 
                  DELETED NUMBER NOT NULL, 
                  UPDATEDAT DATE, 
                  PRIMARY KEY (ID))");

            Db.Connection.Execute(
                @"CREATE TABLE CARS (
                  ID NUMBER GENERATED ALWAYS AS IDENTITY(START WITH 1 INCREMENT BY 1),
                  NAME VARCHAR(256) NOT NULL, 
                  USERID NUMBER NOT NULL, 
                  STATUS NUMBER NOT NULL, 
                  DATA RAW(16) NULL, 
                  PRIMARY KEY (ID))");

            Db.Connection.Execute(
                @"CREATE TABLE ADDRESSES (
                  ID NUMBER GENERATED ALWAYS AS IDENTITY(START WITH 1 INCREMENT BY 1),
                  STREET VARCHAR(256) NOT NULL, 
                  CITYID VARCHAR(256) NOT NULL,  
                  PRIMARY KEY (ID))");

            Db.Connection.Execute(
                @"CREATE TABLE CITIES (
                  IDENTIFIER RAW(16) NOT NULL, 
                  NAME VARCHAR(256) NOT NULL)");

            Db.Connection.Execute(
                @"CREATE TABLE DAB.PHONES (
                  ID NUMBER GENERATED ALWAYS AS IDENTITY(START WITH 1 INCREMENT BY 1),
                  PNUMBER VARCHAR(256) NOT NULL, 
                  ISACTIVE NUMBER(1) NOT NULL, 
                  CODE VARCHAR(256) NOT NULL, 
                  PRIMARY KEY  (ID))");

            Db.Connection.Execute(
                @"CREATE TABLE REPORTS (
                  ID NUMBER NOT NULL, 
                  ANOTHERID NUMBER NOT NULL, 
                  USERID NUMBER NOT NULL,  
                  PRIMARY KEY (ID, ANOTHERID))");

            InitData.Execute(Db);
        }
Beispiel #3
0
        private void InitDb()
        {
            Db.Connection.Execute($"CREATE DATABASE IF NOT EXISTS `{_dbName}`;");
            Db.Connection.Execute($"CREATE DATABASE IF NOT EXISTS DAB;");

            Db.Connection.Execute($"USE `{_dbName}`");

            ClearDb();

            Db.Connection.Execute($"USE `DAB`");
            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Phones` " +
                                  "(`Id` int not null auto_increment, `Number` varchar(256) not null, " +
                                  "`IsActive` boolean not null, `Code` varchar(256) not null, PRIMARY KEY  (`Id`));");

            Db.Connection.Execute($"USE `{_dbName}`");

            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Users` " +
                                  "(`Id` int not null auto_increment, `Name` varchar(256) not null, `AddressId` int not null, `PhoneId` int not null, " +
                                  "`OfficePhoneId` int not null, `Deleted` boolean not null, `UpdatedAt` datetime, PRIMARY KEY  (`Id`));");

            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Cars` " +
                                  "(`Id` int not null auto_increment, `Name` varchar(256) not null, " +
                                  "`UserId` int not null, `Status` int not null, Data binary(16) null, PRIMARY KEY  (`Id`));");

            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Addresses`" +
                                  "(`Id` int not null auto_increment, `Street` varchar(256) not null, " +
                                  "`CityId` varchar(256) not null, PRIMARY KEY  (`Id`));");

            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Cities`" +
                                  "(`Id` int not null auto_increment, `Name` varchar(256) not null, `Identifier` char(36) not null, " +
                                  "PRIMARY KEY  (`Id`));");

            Db.Connection.Execute("CREATE TABLE IF NOT EXISTS `Reports`" +
                                  "(`Id` int not null auto_increment, `AnotherId` int not null, `UserId` int not null, " +
                                  "PRIMARY KEY  (`Id`, `AnotherId`));");


            InitData.Execute(Db);
            var t = 2;
        }