Example #1
0
 public static ICreateTableColumnOptionOrWithColumnSyntax AddCommonColumns
     (this ICreateTableWithColumnOrSchemaOrDescriptionSyntax table)
 {
     return(table
            .WithColumn("Id").AsInt32().PrimaryKey().Identity()
            .WithColumn("CreatedAt").AsDateTime().NotNullable()
            .WithColumn("LastUpdated").AsDateTime().NotNullable());
 }
Example #2
0
 public static ICreateTableColumnOptionOrWithColumnSyntax WithIdColumn(this ICreateTableWithColumnOrSchemaOrDescriptionSyntax table)
 {
     return(table
            .WithColumn("Id")
            .AsInt32()
            .NotNullable()
            .PrimaryKey()
            .Identity());
 }
Example #3
0
        public override void Up()
        {
            var tool = new DataJsonDiff();

            var inTable  = tool.InCommingTables(json, srcJson);
            var outTable = tool.OutCommingTables(json, srcJson);

            var inCol  = tool.InCommingColumns(json, srcJson);
            var outCol = tool.OutCommingColumn(json, srcJson);

            var inRel  = tool.InCommingRelation(json, srcJson);
            var outRel = tool.OutCommingRelation(json, srcJson);

            var builder = Create;

            foreach (var item in inTable)
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax tableBuilder = builder.Table(item);
                tableBuilder.WithColumn("Id").AsGuid();
            }

            foreach (var item in inCol)
            {
                var colOnTableName = FindTableName(item.Key, json.tables);
                foreach (var colItem in item.Value)
                {
                    ICreateColumnOnTableSyntax colBuilder       = Create.Column(colItem.name.Value);
                    ICreateColumnAsTypeSyntax  coOptionlBuilder = colBuilder.OnTable(colOnTableName);
                    //coOptionlBuilder.AsString();
                    ProcessType(colItem.type.Value, coOptionlBuilder);
                }
            }

            foreach (var item in inRel)
            {
                ICreateForeignKeyFromTableSyntax relationBuilder = Create.ForeignKey(item);
                string tableName = json.tables[item.tableId].Value;
                relationBuilder.FromTable(tableName).ForeignColumn("").ToTable("").PrimaryColumn("");
            }

            var DelBuilder = Delete;

            foreach (var item in outTable)
            {
                DelBuilder.Table(item);
            }

            foreach (var item in outCol)
            {
                DelBuilder.Column("").FromTable("");
            }

            foreach (var item in outRel)
            {
                DelBuilder.ForeignKey("").OnTable("");
            }
        }
        //public override void Up()
        //{
        //    var builder = Create;

        //    foreach (var item in inTable)
        //    {
        //        ICreateTableWithColumnOrSchemaOrDescriptionSyntax tableBuilder = builder.Table(item);
        //        tableBuilder.WithColumn("Id").AsGuid();
        //    }

        //    foreach (var item in inCol)
        //    {
        //        var colOnTableName = FindTableName(item.Key, json.tables);
        //        foreach (var colItem in item.Value)
        //        {
        //            ICreateColumnOnTableSyntax colBuilder = Create.Column(colItem.name.Value);
        //            ICreateColumnAsTypeSyntax coOptionlBuilder = colBuilder.OnTable(colOnTableName);
        //            //coOptionlBuilder.AsString();
        //            ProcessType(colItem.type.Value, coOptionlBuilder);
        //        }
        //    }

        //    foreach (var item in inRel)
        //    {
        //        ICreateForeignKeyFromTableSyntax relationBuilder = Create.ForeignKey(item);
        //        string tableName = json.tables[item.tableId].Value;
        //        relationBuilder.FromTable(tableName).ForeignColumn("").ToTable("").PrimaryColumn("");
        //    }

        //}

        public override void Up()
        {
            var tableList = json.table;
            var col       = json.col;
            var reference = json.reference;

            var builder = Create;

            foreach (var tableItem in tableList)
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax tableBuilder = builder.Table(tableItem["name"].Value);

                foreach (var colItem in col[tableItem["name"].Value])
                {
                    ICreateTableColumnAsTypeSyntax column = tableBuilder.WithColumn(colItem.Name);
                    ProcessType(colItem.Value.Value, column);
                }
            }
        }
Example #5
0
        public void Up12()
        {
            var tableList = json.table;
            var col       = json.col;
            var reference = json.reference;

            var builder = Create;

            foreach (var tableItem in tableList)
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax tableBuilder = builder.Table(tableItem["name"].Value);

                //tableBuilder.WithColumn("Id").AsGuid().PrimaryKey();

                foreach (var colItem in col[tableItem["name"].Value])
                {
                    ICreateTableColumnAsTypeSyntax column = tableBuilder.WithColumn(colItem.Name);
                    //ProcessType(colItem.Value.ToString().ToLower(), column);
                }
            }
        }
Example #6
0
        public override void Up()
        {
            string creationTimeColumnName = "CreationTime";
            string updateTimeColumnName   = "UpdateTime";

            string addressTableName           = "Address";
            string allergiesTableName         = "Allergies";
            string patientsTableName          = "Patients";
            string patientAllergiesTableName  = "PatientAllergies";
            string aspNetRolesTableName       = "AspNetRoles";
            string aspNetUsersTableName       = "AspNetUsers";
            string aspNetRoleClaimsTableName  = "AspNetRoleClaims";
            string aspNetUsersClaimsTableName = "AspNetUserClaims";
            string aspNetUserLoginsTableName  = "AspNetUserLogins";
            string aspNetUserRolesTableName   = "AspNetUserRoles";
            string aspNetUserTokensTableName  = "AspNetUserTokens";

            if (!this.Schema.Table(addressTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax addressTable = this.Create.Table(addressTableName);
                addressTable.WithColumn("Id").AsBinary().PrimaryKey().NotNullable();
                addressTable.WithColumn("City").AsString().Nullable();
                addressTable.WithColumn("Coordinates").AsString().Nullable();
                addressTable.WithColumn("Street").AsString().Nullable();
                addressTable.WithColumn("Zip").AsString().Nullable();
                addressTable.WithColumn(creationTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                addressTable.WithColumn(updateTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
            }

            if (!this.Schema.Table(allergiesTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax
                    allergiesTable = this.Create.Table(allergiesTableName);
                allergiesTable.WithColumn("Id").AsBinary().PrimaryKey().NotNullable();
                allergiesTable.WithColumn(creationTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                allergiesTable.WithColumn(updateTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                allergiesTable.WithColumn("Name").AsString().NotNullable();
                allergiesTable.WithColumn("Signs").AsString().NotNullable();
                allergiesTable.WithColumn("Symptoms").AsString().Nullable();
            }

            if (!this.Schema.Table(patientsTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax patientsTable = this.Create.Table(patientsTableName);
                patientsTable.WithColumn("Id").AsBinary().PrimaryKey().NotNullable();
                patientsTable.WithColumn("AddressId").AsBinary().ForeignKey(addressTableName, "Id").Nullable();
                patientsTable.WithColumn("Dob").AsString().NotNullable();
                patientsTable.WithColumn("Email").AsString().Nullable();
                patientsTable.WithColumn("Name").AsString().Nullable();
                patientsTable.WithColumn("Surname").AsString().Nullable();
                patientsTable.WithColumn("MedicalNumber").AsString().Nullable();
                patientsTable.WithColumn(creationTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                patientsTable.WithColumn(updateTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
            }

            if (!this.Schema.Table(patientAllergiesTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax patientAllergiesTable =
                    this.Create.Table(patientAllergiesTableName);
                patientAllergiesTable.WithColumn("IdAllergy").AsBinary().Nullable();
                patientAllergiesTable.WithColumn("IdPatient").AsBinary().Nullable();
                patientAllergiesTable.WithColumn("Id").AsBinary().Unique().NotNullable();
                patientAllergiesTable.WithColumn(creationTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                patientAllergiesTable.WithColumn(updateTimeColumnName).AsDateTime().NotNullable()
                .WithDefaultValue("0001-01-01 00:00:00");
                patientAllergiesTable.WithColumn("AllergiesId").AsBinary()
                .ForeignKey("FK_PatientAllergies_Allergies_AllergiesId", allergiesTableName, "Id")
                .OnDelete(Rule.Cascade).Nullable();
                patientAllergiesTable.WithColumn("PatientsId").AsBinary()
                .ForeignKey("FK_PatientAllergies_Patients_PatientsId", patientsTableName, "Id")
                .OnDelete(Rule.Cascade).Nullable();
                patientAllergiesTable.WithColumn("Note").AsString().NotNullable();
                patientAllergiesTable.WithColumn("LastOcurrence").AsDateTime().NotNullable();
                patientAllergiesTable.WithColumn("AssertedDate").AsDateTime().NotNullable();

                this.Create.PrimaryKey("PK_PatientAllergies").OnTable(patientAllergiesTableName)
                .Columns("IdAllergy", "IdPatient");
            }

            if (!this.Schema.Table(aspNetRolesTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetRolesTable =
                    this.Create.Table(aspNetRolesTableName);
                aspNetRolesTable.WithColumn("Id").AsString().PrimaryKey().NotNullable();
                aspNetRolesTable.WithColumn("Name").AsString().NotNullable();
                aspNetRolesTable.WithColumn("NormalizedName").AsString().Nullable();
                aspNetRolesTable.WithColumn("ConcurrencyStamp").AsString().Nullable();
            }

            if (!this.Schema.Table(aspNetRoleClaimsTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetRoleClaimsTable =
                    this.Create.Table(aspNetRoleClaimsTableName);
                aspNetRoleClaimsTable.WithColumn("Id").AsInt32().PrimaryKey().NotNullable();
                aspNetRoleClaimsTable.WithColumn("RoleId").AsString().NotNullable()
                .ForeignKey("FK_AspNetRoleClaims_AspNetRoles_RoleId", aspNetRolesTableName, "Id");
                aspNetRoleClaimsTable.WithColumn("ClaimType").AsString().Nullable();
                aspNetRoleClaimsTable.WithColumn("ClaimValue").AsString().Nullable();
            }

            if (!this.Schema.Table(aspNetUsersTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetUsersTable =
                    this.Create.Table(aspNetUsersTableName);
                aspNetUsersTable.WithColumn("Id").AsString().PrimaryKey().NotNullable();
                aspNetUsersTable.WithColumn("UserName").AsString().Nullable();
                aspNetUsersTable.WithColumn("NormalizedUserName").AsString().Nullable();
                aspNetUsersTable.WithColumn("Email").AsString().Nullable();
                aspNetUsersTable.WithColumn("NormalizedEmail").AsString().Nullable();
                aspNetUsersTable.WithColumn("EmailConfirmed").AsInt32().NotNullable();
                aspNetUsersTable.WithColumn("PasswordHash").AsString().Nullable();
                aspNetUsersTable.WithColumn("SecurityStamp").AsString().Nullable();
                aspNetUsersTable.WithColumn("ConcurrencyStamp").AsString().Nullable();
                aspNetUsersTable.WithColumn("PhoneNumber").AsString().Nullable();
                aspNetUsersTable.WithColumn("PhoneNumberConfirmed").AsInt32().NotNullable();
                aspNetUsersTable.WithColumn("TwoFactorEnabled").AsInt32().NotNullable();
                aspNetUsersTable.WithColumn("LockoutEnd").AsString().Nullable();
                aspNetUsersTable.WithColumn("LockoutEnabled").AsInt32().NotNullable();
                aspNetUsersTable.WithColumn("AccessFailedCount").AsInt32().NotNullable();
                aspNetUsersTable.WithColumn("LastName").AsString().Nullable();
                aspNetUsersTable.WithColumn("Name").AsString().Nullable();
                aspNetUsersTable.WithColumn("RefreshToken").AsString().Nullable();
            }

            if (!this.Schema.Table(aspNetUsersClaimsTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetUserClaimsTable =
                    this.Create.Table(aspNetUsersClaimsTableName);
                aspNetUserClaimsTable.WithColumn("Id").AsInt32().PrimaryKey().NotNullable();
                aspNetUserClaimsTable.WithColumn("UserId").AsString()
                .ForeignKey("FK_AspNetUserClaims_AspNetUsers_UserId", aspNetUsersTableName, "Id")
                .OnDelete(Rule.Cascade).NotNullable();
                aspNetUserClaimsTable.WithColumn("ClaimType").AsString().Nullable();
                aspNetUserClaimsTable.WithColumn("ClaimValue").AsString().Nullable();
            }

            if (!this.Schema.Table(aspNetUserLoginsTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetUserLoginsTable =
                    this.Create.Table(aspNetUserLoginsTableName);
                aspNetUserLoginsTable.WithColumn("LoginProvider").AsString().NotNullable();
                aspNetUserLoginsTable.WithColumn("ProviderKey").AsString().NotNullable();
                aspNetUserLoginsTable.WithColumn("ProviderDisplayName").AsString().Nullable();
                aspNetUserLoginsTable.WithColumn("UserId").AsString().NotNullable()
                .ForeignKey("FK_AspNetUserLogins_AspNetUsers_UserId", aspNetUsersTableName, "Id")
                .OnDelete(Rule.Cascade);

                this.Create.PrimaryKey("PK_AspNetUserClaims").OnTable(aspNetUserLoginsTableName)
                .Columns("LoginProvider", "ProviderKey");
            }

            if (!this.Schema.Table(aspNetUserRolesTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetUserRolesTable =
                    this.Create.Table(aspNetUserRolesTableName);
                aspNetUserRolesTable.WithColumn("UserId").AsString().NotNullable()
                .ForeignKey("FK_AspNetUserRoles_AspNetUsers_UserId", aspNetUsersTableName, "Id")
                .OnDelete(Rule.Cascade);
                aspNetUserRolesTable.WithColumn("RoleId").AsString().NotNullable()
                .ForeignKey("FK_AspNetUserRoles_AspNetRoles_RoleId", aspNetRolesTableName, "Id")
                .OnDelete(Rule.Cascade);

                this.Create.PrimaryKey("PK_AspNetUserRoles").OnTable(aspNetUserRolesTableName)
                .Columns("UserId", "RoleId");
            }

            if (!this.Schema.Table(aspNetUserTokensTableName).Exists())
            {
                ICreateTableWithColumnOrSchemaOrDescriptionSyntax aspNetUserTokensTable =
                    this.Create.Table(aspNetUserTokensTableName);
                aspNetUserTokensTable.WithColumn("UserId").AsString()
                .ForeignKey("FK_AspNetUserTokens_AspNetUsers_UserId", aspNetUsersTableName, "Id").NotNullable();
                aspNetUserTokensTable.WithColumn("LoginProvider").AsString().NotNullable();
                aspNetUserTokensTable.WithColumn("Name").AsString().NotNullable();
                aspNetUserTokensTable.WithColumn("Value").AsString().Nullable();

                this.Create.PrimaryKey("PK_AspNetUserTokens").OnTable(aspNetUserTokensTableName)
                .Columns("UserId", "LoginProvider", "Name");
            }
        }
Example #7
0
 public static ICreateTableColumnOptionOrWithColumnSyntax LucidPrimaryKey(this ICreateTableWithColumnOrSchemaOrDescriptionSyntax builder, string tableName, string columnName)
 {
     return(builder.WithColumn(columnName).AsInt32().PrimaryKey("PK_" + tableName + "_" + columnName).Identity());
 }