Ejemplo n.º 1
0
        /// <summary>Creates a foreignkey based on some defaults</summary>
        /// <param name="schemaBuilder">The schemaBuilder</param>
        /// <param name="srcRecordType">The type of the source contentTypeRecord, which will resolve to the source table</param>
        /// <param name="destRecordType">The type of the destination contentTypeRecord, which will resolve to the destination table</param>
        /// <param name="srcColumn">Overrides the source column name. Defaults to 'DestinationContentTypeRecord_Id'</param>
        /// <param name="destColumn">Overrides the destination column name</param>
        /// <param name="destModule">Optional. Specify the full module name if the destination table is from another module</param>
        public static void CreateForeignKey(this SchemaBuilder schemaBuilder, Type srcRecordType, Type destRecordType, string srcColumn = null, string destColumn = "Id", string destModule = null)
        {
            var foreignKeyName = CreateForeignKeyName(srcRecordType, destRecordType, srcColumn, destColumn, destModule);
            var srcTableName   = srcRecordType.Name;
            var destTableName  = destRecordType.Name;

            srcColumn = string.IsNullOrEmpty(srcColumn) ? string.Format("{0}_Id", destTableName) : srcColumn;

            if (!string.IsNullOrEmpty(destModule))
            {
                schemaBuilder.CreateForeignKey(
                    foreignKeyName,
                    srcTableName,
                    new[] { srcColumn },
                    destModule,
                    destTableName,
                    new[] { destColumn });
            }
            else
            {
                schemaBuilder.CreateForeignKey(
                    foreignKeyName,
                    srcTableName,
                    new[] { srcColumn },
                    destTableName,
                    new[] { destColumn });
            }
        }
Ejemplo n.º 2
0
        public int UpdateFrom5()
        {
            SchemaBuilder.CreateTable("OrderPartRecord", t => t
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("CustomerId", c => c.NotNull())
                                      .Column <DateTime>("CreatedAt", c => c.NotNull())
                                      .Column <decimal>("SubTotal", c => c.NotNull())
                                      .Column <decimal>("Vat", c => c.NotNull())
                                      .Column <string>("Status", c => c.WithLength(50).NotNull())
                                      .Column <string>("PaymentServiceProviderResponse", c => c.WithLength(null))
                                      .Column <string>("PaymentReference", c => c.WithLength(50))
                                      .Column <DateTime>("PaidAt", c => c.Nullable())
                                      .Column <DateTime>("CompletedAt", c => c.Nullable())
                                      .Column <DateTime>("CancelledAt", c => c.Nullable())
                                      );

            SchemaBuilder.CreateTable("OrderDetailPartRecord", t => t
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("OrderRecord_Id", c => c.NotNull())
                                      .Column <int>("ProductId", c => c.NotNull())
                                      .Column <int>("Quantity", c => c.NotNull())
                                      .Column <decimal>("UnitPrice", c => c.NotNull())
                                      .Column <decimal>("VatRate", c => c.NotNull())
                                      );

            SchemaBuilder.CreateForeignKey("Order_Customer", "OrderPartRecord", new[] { "CustomerId" }, "CustomerPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Order", "OrderDetailPartRecord", new[] { "OrderRecord_Id" }, "OrderPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Product", "OrderDetailPartRecord", new[] { "ProductId" }, "ProductPartRecord", new[] { "Id" });

            return(6);
        }
Ejemplo n.º 3
0
        public int UpdateFrom7()
        {
            SchemaBuilder.CreateTable("OrderRecord", t => t
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("CustomerId", c => c.NotNull())
                                      .Column <DateTime>("CreatedAt", c => c.NotNull())
                                      .Column <string>("Status", c => c.WithLength(50).NotNull())
                                      .Column <decimal>("SubTotal", c => c.NotNull())
                                      .Column <decimal>("Vat", c => c.NotNull())
                                      .Column <DateTime>("CompletedAt", c => c.Nullable())
                                      .Column <DateTime>("CancelledAt", c => c.Nullable())
                                      );

            SchemaBuilder.CreateTable("OrderDetailRecord", t => t
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("OrderRecord_Id", c => c.NotNull())
                                      .Column <int>("BookId", c => c.NotNull())
                                      .Column <int>("Quantity", c => c.NotNull())
                                      .Column <decimal>("UnitPrice", c => c.NotNull())
                                      .Column <decimal>("VatRate", c => c.NotNull())
                                      );

            SchemaBuilder.CreateForeignKey("Order_Customer", "OrderRecord", new[] { "CustomerId" }, "CustomerPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Order", "OrderDetailRecord", new[] { "OrderRecord_Id" }, "OrderRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Book", "OrderDetailRecord", new[] { "BookId" }, "BookPartRecord", new[] { "Id" });

            return(8);
        }
Ejemplo n.º 4
0
        public int Create()
        {
            SchemaBuilder.CreateTable("PaymentPartRecord", table => table
                                      .ContentPartRecord()
                                      );

            SchemaBuilder.CreateTable("PaymentTransactionRecord", table => table
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("PaymentPartRecord_Id", c => c.NotNull())
                                      .Column <DateTime>("Date")
                                      .Column <decimal>("Amount")
                                      .Column <string>("Method")
                                      .Column <string>("TransactionId")
                                      .Column <string>("Status", c => c.WithLength(16))
                                      .Column <string>("Data", c => c.Unlimited())
                                      );

            SchemaBuilder.CreateForeignKey("FK_PaymentTransactionRecord_PaymentPartRecord", "PaymentTransactionRecord", new[] { "PaymentPartRecord_Id" }, "PaymentPartRecord", new[] { "Id" });

            ContentDefinitionManager.AlterTypeDefinition("Order", type => type
                                                         .WithPart("PaymentPart")
                                                         );

            return(1);
        }
Ejemplo n.º 5
0
        public void CreateFields(string tableName, long[] fieldIds)
        {
            var table = Get(tableName);

            Check.Require(table.Created, $"表 [{table.Table}.{table.Name}] 未构建,请先构建表");
            var fields = fieldService.Gets(tableName, fieldIds);

            Session.BeginTransaction();
            try
            {
                var sb = new SchemaBuilder(Session).AlterTable(table.Table, t =>
                {
                    foreach (var item in fields)
                    {
                        t.AddColumn(item.Field, GetDbType(item.Type), c =>
                        {
                            if (item.Type == FieldType.key)
                            {
                                c.PrimaryKey();
                            }
                            if (!item.IsNull)
                            {
                                c.NotNull();
                            }
                            if (item.Default.HasValue())
                            {
                                c.WithDefault(item.Default);
                            }
                            if (item.Length.HasValue)
                            {
                                c.WithLength(item.Length);
                            }
                            if (item.Type == FieldType.text)
                            {
                                c.Unlimited();
                            }
                        });
                    }
                });

                foreach (var fk in fields.Where(f => f.Type == FieldType.fkey))
                {
                    sb.CreateForeignKey(
                        $"FK_{table.Table}_{fk.Field}_{fk.Ref}",
                        table.Table,
                        fk.Field,
                        fk.Ref,
                        "id");
                }

                UpdateCreated(table.Table, fieldIds, 1);

                Session.Commit();
            }
            catch (Exception ex)
            {
                Session.Rollback();
                throw new AceException(ex.GetMessage());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the database schema for a <see cref="DynamicTarget"/>
        /// </summary>
        /// <returns></returns>
        public override int Create()
        {
            try
            {
                var dynamicTarget = Target as DynamicTarget;
                if (dynamicTarget == null)
                {
                    return(0);
                }

                // create table for target type
                SchemaBuilder.CreateTable(dynamicTarget.DbSchemaName, table => table
                                          .DatasetRecord()
                                          .DatasetReferenceRecord()
                                          .AddColumns(dynamicTarget.Columns.ToArray())
                                          );
                // create FK to datasets table
                SchemaBuilder.CreateForeignKey(
                    string.Format("FK_{0}_Datasets", dynamicTarget.DbSchemaName),
                    dynamicTarget.DbSchemaName,
                    new[] { "Dataset_id" },
                    typeof(Dataset).GetCustomAttribute <EntityTableNameAttribute>().TableName,
                    new[] { "Id" });
            }
            catch (Exception exc)
            {
                SessionLogger.Write(exc);
                return(0);
            }

            return(1);
        }
Ejemplo n.º 7
0
        public int Create()
        {
            SchemaBuilder.CreateTable(typeof(LanguageRecord).Name,
                                      table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <string>("Code", c => c.WithLength(10))
                                      .Column <string>("Name", c => c.WithLength(150))
                                      );

            SchemaBuilder.CreateTable(typeof(FaqSectionRecord).Name,
                                      table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <string>("Name", c => c.WithLength(150))
                                      );

            SchemaBuilder.CreateTable(typeof(FaqEntryPartRecord).Name,
                                      table => table
                                      .ContentPartRecord()
                                      .Column <string>("Question", c => c.Unlimited())
                                      .Column <string>("Answer", c => c.Unlimited())
                                      .Column <int>("LanguageRecord_Id")
                                      .Column <int>("FaqSectionRecord_Id")
                                      );

            SchemaBuilder.CreateForeignKey("FaqEntry_Language", typeof(FaqEntryPartRecord).Name, new[] { "LanguageRecord_Id" }, typeof(LanguageRecord).Name, new[] { "Id" });
            SchemaBuilder.CreateForeignKey("FaqEntry_FaqSection", typeof(FaqEntryPartRecord).Name, new[] { "FaqSectionRecord_Id" }, typeof(FaqSectionRecord).Name, new[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition(typeof(FaqEntryPart).Name, part => part
                                                         .Attachable()
                                                         );

            ContentDefinitionManager.AlterTypeDefinition("FaqEntry", type => type
                                                         .WithPart(typeof(FaqEntryPart).Name)
                                                         .WithPart("CommonPart")
                                                         .WithPart("BodyPart")
                                                         );

            ContentDefinitionManager.AlterTypeDefinition("FaqEntry", type => type
                                                         .WithPart("BodyPart")
                                                         );

            SchemaBuilder.DropForeignKey(typeof(FaqEntryPartRecord).Name, "FaqEntry_Language");

            SchemaBuilder.AlterTable(typeof(FaqEntryPartRecord).Name,
                                     table => table
                                     .DropColumn("LanguageRecord_Id"));

            SchemaBuilder.AlterTable(typeof(FaqEntryPartRecord).Name,
                                     table => table
                                     .AddColumn <string>("Language", c => c
                                                         .WithLength(10)
                                                         .NotNull()
                                                         .WithDefault("en-MY"))

                                     );

            SchemaBuilder.AlterTable(typeof(FaqSectionRecord).Name, table => table.AddColumn <string>("SectionCulture", c => c.NotNull().WithDefault("en-MY").WithLength(10)));

            return(4);
        }
Ejemplo n.º 8
0
        public int Create()
        {
            SchemaBuilder.CreateTable("ShoppingCartRecord", table => table
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <string>("Guid", c => c.WithLength(36))
                                      .Column <DateTime>("ModifiedUtc")
                                      .Column <int>("OwnerId", c => c.Nullable())
                                      .Column <string>("Data", c => c.Unlimited()));

            SchemaBuilder.CreateTable("ShoppingCartItemRecord", table => table
                                      .Column <int>("Id", c => c.PrimaryKey().Identity())
                                      .Column <int>("ShoppingCartRecord_Id")
                                      .Column <string>("ItemType")
                                      .Column <int>("ItemId", c => c.NotNull())
                                      .Column <int>("Quantity"));

            SchemaBuilder.CreateForeignKey("FK_ShoppingCartItemRecord_ShoppingCartRecord", "ShoppingCartItemRecord", new[] { "ShoppingCartRecord_Id" }, "ShoppingCartRecord", new[] { "Id" });

            ContentDefinitionManager.AlterTypeDefinition("ShoppingCartWidget", type => type
                                                         .WithPart("CommonPart")
                                                         .WithPart("ShoppingCartWidgetPart")
                                                         .WithPart("WidgetPart")
                                                         .WithSetting("Stereotype", "Widget")
                                                         );

            return(1);
        }
Ejemplo n.º 9
0
        public int Create()
        {
            SchemaBuilder.CreateTable(typeof(ExtendedAliasRecord).Name, table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("AliasRecord_Id", column => column.NotNull())
                                      .Column <string>("RouteName", column => column
                                                       .NotNull()
                                                       .WithLength(50))
                                      );

            SchemaBuilder.CreateForeignKey("ExtendedAliasRecord_AliasRecord", "ExtendedAliasRecord", new[] { "AliasRecord_Id" }, "Orchard.Alias", "AliasRecord", new[] { "Id" });

            return(1);
        }
Ejemplo n.º 10
0
        public int Create()
        {
            SchemaBuilder.CreateTable(
                "BundlePartRecord",
                table => table.ContentPartRecord());

            SchemaBuilder.CreateTable(
                "BundleProductsRecord", table => table
                .Column <int>("Id", column => column.PrimaryKey().Identity())
                .Column <int>("BundlePartRecord_Id")
                .Column <int>("ContentItemRecord_Id"));

            SchemaBuilder.CreateForeignKey(
                "FK_BundleProductsBundle",
                "BundleProductsRecord", new[] { "BundlePartRecord_Id" },
                "BundlePartRecord", new[] { "Id" });

            SchemaBuilder.CreateForeignKey(
                "FK_BundleProductsProduct",
                "BundleProductsRecord", new[] { "ContentItemRecord_Id" },
                "Orchard.Framework", "ContentItemRecord", new[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition(
                "BundlePart", builder => builder
                .Attachable());

            ContentDefinitionManager.AlterTypeDefinition(
                "Bundle", cfg => cfg
                .WithPart("Bundle")
                .WithPart("CommonPart")
                .WithPart("TitlePart")
                .WithPart("AutoroutePart", builder => builder
                          .WithSetting("AutorouteSettings.AllowCustomPattern", "true")
                          .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
                          .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: '{Content.Slug}', Description: 'my-bundle'}]")
                          .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
                .WithPart("BodyPart")
                .WithPart("ProductPart")
                .WithPart("BundlePart")
                .WithPart("TagsPart")
                .Creatable()
                .Indexed());

            ContentDefinitionManager.AlterPartDefinition("Bundle",
                                                         builder => builder
                                                         .WithField("ProductImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Product Image")));

            return(1);
        }
Ejemplo n.º 11
0
        public int UpdateFrom10()
        {
            SchemaBuilder.CreateTable("OrderPartRecord", t => t
                                      .ContentPartRecord()
                                      .Column <int>("CustomerId", c => c.NotNull())
                                      .Column <DateTime>("CreatedAt", c => c.NotNull())
                                      .Column <decimal>("SubTotal", c => c.NotNull())
                                      .Column <decimal>("Vat", c => c.NotNull())
                                      .Column <string>("Status", c => c.WithLength(50).NotNull())
                                      .Column <string>("PaymentServiceProviderResponse", c => c.WithLength(null))
                                      .Column <string>("PaymentReference", c => c.WithLength(50))
                                      .Column <DateTime>("PaidAt", c => c.Nullable())
                                      .Column <DateTime>("CompletedAt", c => c.Nullable())
                                      .Column <DateTime>("CancelledAt", c => c.Nullable())
                                      );

            SchemaBuilder.CreateTable("OrderDetailPartRecord", t => t
                                      .ContentPartRecord()
                                      .Column <int>("OrderRecord_Id", c => c.NotNull())
                                      .Column <int>("ProductId", c => c.NotNull())
                                      .Column <int>("Quantity", c => c.NotNull())
                                      .Column <decimal>("UnitPrice", c => c.NotNull())
                                      .Column <decimal>("VatRate", c => c.NotNull())
                                      );

            SchemaBuilder.CreateForeignKey("Order_Customer", "OrderPartRecord", new[] { "CustomerId" }, "CustomerPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Order", "OrderDetailPartRecord", new[] { "OrderRecord_Id" }, "OrderPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("OrderDetail_Product", "OrderDetailPartRecord", new[] { "ProductId" }, "ProductPartRecord", new[] { "Id" });


            // Create (or alter) a part called "ProductPart" and configure it to be "attachable".
            ContentDefinitionManager.AlterPartDefinition("OrderPart", part => part
                                                         .Attachable(false));
            // Create (or alter) a part called "ProductPart" and configure it to be "attachable".
            ContentDefinitionManager.AlterPartDefinition("OrderDetailPart", part => part
                                                         .Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Order", type => type
                                                         .WithPart("CommonPart")
                                                         .WithPart("OrderPart"));

            ContentDefinitionManager.AlterTypeDefinition("OrderDetail", type => type
                                                         .WithPart("CommonPart")
                                                         .WithPart("OrderDetailPart"));

            return(11);
        }
        public int Create()
        {
            //Create the tables
            SchemaBuilder.CreateTable(typeof(PerformanceMonitorRecord).Name, table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <string>("CategoryName")
                                      .Column <string>("InstanceName", c => c.Nullable())
                                      .Column <string>("CounterName")
                                      .Column <string>("NodeName")
                                      .Column <string>("IpAddress")
                                      .Column <string>("Duration")
                                      .Column <int>("SampleInterval")
                                      .Column <int>("Threshold")
                                      .Column <bool>("ThresholdWhen")
                                      .Column <DateTime>("Created")
                                      .Column <string>("CreatedBy")
                                      .Column <bool>("IsEnabled")
                                      .Column <string>("InitialValue")
                                      .Column <string>("LastValue")
                                      .Column <DateTime>("StartTime")
                                      .Column <DateTime>("EndTime")
                                      .Column <string>("DurationCount")
                                      .Column <double>("Mean")
                                      .Column <double>("Minimum")
                                      .Column <double>("Maximum"))
            .AlterTable(typeof(PerformanceMonitorRecord).Name, table => table
                        .CreateIndex("IDX_ID", new[] { "Id" }));

            SchemaBuilder.CreateTable(typeof(PerformanceMonitorDataRecord).Name, table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("PerformanceMonitorRecord_Id")
                                      .Column <string>("Count")
                                      .Column <DateTime>("HeartBeat")
                                      .Column <string>("Ticks")
                                      .Column <bool>("PassedThreshold")
                                      .Column <int>("PassedThresholdValue")
                                      );

            SchemaBuilder.CreateForeignKey(
                "FK_PerformanceMonitorDataRecord_PerformanceMonitorRecord"
                , "PerformanceMonitorDataRecord", new[] { "PerformanceMonitorRecord_Id" }
                , "PerformanceMonitorRecord", new[] { "Id" }
                );

            return(1);
        }
Ejemplo n.º 13
0
        public int Create()
        {
            SchemaBuilder.CreateTable("QuestionnairePartRecord", table => table
                                      .ContentPartRecord());

            SchemaBuilder.CreateTable("QuestionRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      .Column <string>("Question", col => col.WithLength(200))
                                      .Column <string>("QuestionType", col => col.WithLength(20))
                                      .Column <bool>("Published", col => col.WithDefault(true))
                                      .Column <int>("Position")
                                      .Column <int>("QuestionnairePartRecord_Id"));

            SchemaBuilder.CreateTable("AnswerRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      .Column <string>("Answer", col => col.WithLength(200))
                                      .Column <bool>("Published", col => col.WithDefault(true))
                                      .Column <int>("Position")
                                      .Column <int>("QuestionRecord_Id"));

            SchemaBuilder.CreateTable("UserAnswersRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      .Column <int>("User_Id")
                                      .Column <int>("QuestionRecord_Id")
                                      .Column <int>("AnswerRecord_Id")
                                      .Column <string>("AnswerText", col => col.WithLength(200))
                                      .Column <DateTime>("AnswerDate"));

            SchemaBuilder.CreateForeignKey("UserAnswersAnswer_Answer", "UserAnswersRecord", new string[] { "AnswerRecord_Id" }, "AnswerRecord", new string[] { "Id" });
            SchemaBuilder.CreateForeignKey("UserAnswersQuestion_Question", "UserAnswersRecord", new string[] { "QuestionRecord_Id" }, "QuestionRecord", new string[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition(typeof(QuestionnairePart).Name, cfg => cfg
                                                         .Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Questionnaire", cfg => cfg
                                                         .WithPart(typeof(QuestionnairePart).Name)
                                                         .WithPart("CommonPart")
                                                         .WithPart("LocalizationPart")
                                                         .WithPart("TitlePart")
                                                         .WithPart("BodyPart")
                                                         .WithPart("AutoroutePart")
                                                         .Creatable()
                                                         .Draftable());

            return(1);
        }
        public int UpdateFrom4()
        {
            SchemaBuilder.CreateTable("CustomerRecord", t => t
                                      .ContentPartRecord()
                                      .Column <string>("FirstName", c => c.WithLength(50))
                                      .Column <string>("LastName", c => c.WithLength(50))
                                      .Column <string>("Title", c => c.WithLength(10))
                                      .Column <DateTime>("CreatedAt", c => c.NotNull())
                                      );

            SchemaBuilder.CreateTable("AddressRecord", t => t
                                      .ContentPartRecord()
                                      .Column <int>("CustomerId")
                                      .Column <string>("Type", c => c.WithLength(50))
                                      );

            SchemaBuilder.CreateForeignKey("Address_Customer", "AddressRecord", new[] { "CustomerId" }, "CustomerRecord",
                                           new[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition(typeof(CustomerPart).Name, p => p
                                                         .Attachable(false)
                                                         .WithField("Phone", f => f.OfType(typeof(TextField).Name))
                                                         );

            ContentDefinitionManager.AlterTypeDefinition("Customer", t => t
                                                         .WithPart(typeof(CustomerPart).Name)
                                                         .WithPart(typeof(UserPart).Name)
                                                         );

            ContentDefinitionManager.AlterPartDefinition(typeof(AddressPart).Name, p => p
                                                         .Attachable(false)
                                                         .WithField("Name", f => f.OfType(typeof(TextField).Name))
                                                         .WithField("AddressLine1", f => f.OfType(typeof(TextField).Name))
                                                         .WithField("AddressLine2", f => f.OfType(typeof(TextField).Name))
                                                         .WithField("Zipcode", f => f.OfType(typeof(TextField).Name))
                                                         .WithField("City", f => f.OfType(typeof(TextField).Name))
                                                         .WithField("Country", f => f.OfType(typeof(TextField).Name))
                                                         );

            ContentDefinitionManager.AlterTypeDefinition("Address", t => t
                                                         .WithPart(typeof(AddressPart).Name)
                                                         );

            return(5);
        }
Ejemplo n.º 15
0
 public int UpdateFrom14()
 {
     SchemaBuilder.CreateTable("ProviderAttributeRecord",
                               table => table
                               .Column <int>("Id", column => column.PrimaryKey().Identity())
                               .Column <int>("ProviderId")
                               .Column <string>("AttributeKey")
                               .Column <string>("AttributeValue")
                               );
     SchemaBuilder.AlterTable("ProviderAttributeRecord",
                              table => table.AddUniqueConstraint("UC_ProviderAttributeRecord_1", new string[] { "ProviderId", "AttributeKey" })
                              );
     SchemaBuilder.CreateForeignKey(
         "FK_ProviderAttributeProvider",
         "ProviderAttributeRecord", new[] { "ProviderId" },
         "ProviderConfigurationRecord", new[] { "Id" });
     return(15);
 }
Ejemplo n.º 16
0
        public int Create()
        {
            SchemaBuilder.CreateTable(
                "CustomSortRecord",
                table => table
                .Column <int>("Id", column => column.PrimaryKey().Identity())
                .Column <string>("Name"));

            SchemaBuilder.CreateTable(
                "CustomSortOrderRecord",
                table => table
                .ContentPartRecord()
                .Column <int>("CustomSortRecord_Id")
                .Column <int>("SortOrder"));

            SchemaBuilder.CreateForeignKey("OrderToSort", "Vandelay.Industries",
                                           "CustomSortOrderRecord", new[] { "CustomSortRecord_Id" },
                                           "CustomSortRecord", new[] { "Id" });

            SchemaBuilder.AlterTable("CustomSortOrderRecord", table => table
                                     .CreateIndex("SortOrderIndex", new[] { "SortOrder" }));

            return(1);
        }
Ejemplo n.º 17
0
        public int Create()
        {
            // Attendees
            SchemaBuilder.CreateTable("AttendeePartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <string>("FirstName", c => c.WithLength(50))
                                      .Column <string>("LastName", c => c.WithLength(50)));

            ContentDefinitionManager.AlterPartDefinition("AttendeePart", part => part.Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Attendee", type => type
                                                         .WithPart("AttendeePart")
                                                         .WithPart("UserPart"));

            // Events
            SchemaBuilder.CreateTable("EventPartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <string>("Name", c => c.WithLength(50))
                                      .Column <string>("Description", c => c.WithLength(256)));

            ContentDefinitionManager.AlterPartDefinition("EventPart", part => part.Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Event", type => type.WithPart("EventPart"));

            // Cups
            SchemaBuilder.CreateTable("CupPartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <DateTime>("Date")
                                      .Column <string>("Title", c => c.WithLength(50)));

            ContentDefinitionManager.AlterPartDefinition("CupPart", part => part.Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Cup", type => type.WithPart("CupPart"));

            // Event order
            SchemaBuilder.CreateTable("EventOrderRecord", table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("CupPartRecord_id")
                                      .Column <int>("EventPartRecord_id")
                                      .Column <int>("SortOrder"));

            SchemaBuilder.CreateForeignKey("EventOrder_Cup", "EventOrderRecord", new[] { "CupPartRecord_id" }, "CupPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("EventOrder_Event", "EventOrderRecord", new[] { "EventPartRecord_id" }, "EventPartRecord", new[] { "Id" });

            // Cup placement
            SchemaBuilder.CreateTable("CupPlaceRecord", table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("CupPartRecord_id")
                                      .Column <int>("Place")
                                      .Column <int>("Points"));

            SchemaBuilder.CreateForeignKey("CupPlace_Cup", "CupPlaceRecord", new[] { "CupPartRecord_id" }, "CupPartRecord", new[] { "Id" });

            // Teams
            SchemaBuilder.CreateTable("TeamPartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <int>("CupId")
                                      .Column <string>("Name", c => c.WithLength(50)));

            SchemaBuilder.CreateForeignKey("Team_Cup", "TeamPartRecord", new[] { "CupId" }, "CupPartRecord", new[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition("TeamPart", part => part.Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Team", type => type.WithPart("TeamPart"));

            // Team attendee
            SchemaBuilder.CreateTable("TeamAttendeeRecord", table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("TeamPartRecord_id")
                                      .Column <int>("AttendeePartRecord_id"));

            SchemaBuilder.CreateForeignKey("TeamAttendee_Team", "TeamAttendeeRecord", new[] { "TeamPartRecord_id" }, "TeamPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("TeamAttendee_Attendee", "TeamAttendeeRecord", new[] { "AttendeePartRecord_id" }, "AttendeePartRecord", new[] { "Id" });

            // Scores
            SchemaBuilder.CreateTable("ScorePartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <int>("CupId")
                                      .Column <int>("EventId")
                                      .Column <string>("Notes"));

            SchemaBuilder.CreateForeignKey("Score_Cup", "ScorePartRecord", new[] { "CupId" }, "CupPartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("Score_Event", "ScorePartRecord", new[] { "EventId" }, "EventPartRecord", new[] { "Id" });

            ContentDefinitionManager.AlterPartDefinition("ScorePart", part => part.Attachable(false));

            ContentDefinitionManager.AlterTypeDefinition("Score", type => type.WithPart("ScorePart"));

            // Score team
            SchemaBuilder.CreateTable("TeamScoreRecord", table => table
                                      .Column <int>("Id", column => column.PrimaryKey().Identity())
                                      .Column <int>("ScorePartRecord_id")
                                      .Column <int>("TeamPartRecord_id")
                                      .Column <int>("Score")
                                      .Column <int>("Penalties"));

            SchemaBuilder.CreateForeignKey("TeamScore_Score", "TeamScoreRecord", new[] { "ScorePartRecord_id" }, "ScorePartRecord", new[] { "Id" });
            SchemaBuilder.CreateForeignKey("TeamScore_Team", "TeamScoreRecord", new[] { "TeamPartRecord_id" }, "TeamPartRecord", new[] { "Id" });

            return(1);
        }
Ejemplo n.º 18
0
        public int Create()
        {
            SchemaBuilder.CreateTable("QuestionnairePartRecord", table => table
                                      .ContentPartRecord()
                                      // UpdateFrom2: adding columns.
                                      .Column <bool>("MustAcceptTerms", col => col.WithDefault(false))
                                      .Column <string>("TermsText", col => col.Unlimited())
                                      .Column <bool>("UseRecaptcha", col => col.WithDefault(false))
                                      );


            SchemaBuilder.CreateTable("QuestionRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      // UpdateFrom17: altering columns.
                                      //.Column<string>("Question", col => col.WithLength(200))
                                      .Column <string>("Question", col => col.WithLength(500))
                                      .Column <string>("QuestionType", col => col.WithLength(20))
                                      .Column <bool>("Published", col => col.WithDefault(true))
                                      .Column <int>("Position")
                                      .Column <int>("QuestionnairePartRecord_Id")
                                      // UpdateFrom2: adding columns.
                                      .Column <string>("Section", col => col.WithLength(200))
                                      .Column <string>("Condition", col => col.Unlimited())
                                      .Column <string>("AnswerType", col => col.WithLength(50))
                                      .Column <bool>("IsRequired", col => col.WithDefault(true))
                                      .Column <string>("ConditionType", col => col.WithLength(50))
                                      // UpdateFrom14: adding columns.
                                      .Column <string>("AllFiles", column => column.Unlimited())
                                      // UpdateFrom26: adding columns.
                                      // UpdateFrom31: renaming columns.
                                      //.Column<string>("Identifier", column => column.Unlimited())
                                      .Column <string>("GUIdentifier", column => column.Unlimited())
                                      );


            SchemaBuilder.CreateTable("AnswerRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      // UpdateFrom24: altering columns.
                                      //.Column<string>("Answer", col => col.WithLength(200))
                                      .Column <string>("Answer", col => col.WithLength(1200))
                                      .Column <bool>("Published", col => col.WithDefault(true))
                                      .Column <int>("Position")
                                      .Column <int>("QuestionRecord_Id")
                                      // UpdateFrom4: adding columns.
                                      .Column <bool>("CorrectResponse", col => col.WithDefault(false))
                                      // UpdateFrom14: adding columns.
                                      .Column <string>("AllFiles", column => column.Unlimited())
                                      // UpdateFrom26: adding columns.
                                      // UpdateFrom31: renaming columns.
                                      //.Column<string>("Identifier", column => column.Unlimited())
                                      .Column <string>("GUIdentifier", column => column.Unlimited())
                                      );


            SchemaBuilder.CreateTable("UserAnswersRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      .Column <int>("User_Id")
                                      .Column <int>("QuestionRecord_Id")
                                      .Column <int>("AnswerRecord_Id")
                                      // UpdateFrom24: altering columns.
                                      //.Column<string>("AnswerText", col => col.WithLength(200))
                                      .Column <string>("AnswerText", col => col.WithLength(1200))
                                      .Column <DateTime>("AnswerDate")
                                      // UpdateFrom1: adding columns.
                                      // UpdateFrom23: altering columns.
                                      //.Column<string>("QuestionText", col => col.WithLength(200))
                                      .Column <string>("QuestionText", col => col.WithLength(500))
                                      // UpdateFrom2: adding columns.
                                      .Column <int>("QuestionnairePartRecord_Id")
                                      // UpdateFrom25: altering columns.
                                      //.Column<string>("SessionID", col => col.WithLength(24))
                                      .Column <string>("SessionID", col => col.WithLength(400))
                                      // UpdateFrom20: adding columns.
                                      .Column <string>("Context", col => col.WithLength(255))
                                      // UpdateFrom27: adding columns.
                                      .Column <string>("AnswerInstance", column => column.WithLength(64))
                                      // UpdateFrom28: adding columns.
                                      .Column <string>("QuestionType", col => col.WithLength(20))
                                      );

            // UpdateFrom28: creating indexes.
            SchemaBuilder
            .AlterTable("UserAnswersRecord", table => table
                        .CreateIndex("IX_User_Id", "User_Id"))
            .AlterTable("UserAnswersRecord", table => table
                        .CreateIndex("IX_QuestionnairePartRecord_Id", "QuestionnairePartRecord_Id"))
            .AlterTable("UserAnswersRecord", table => table
                        .CreateIndex("IX_AnswerInstance", "AnswerInstance"));


            // UpdateFrom5: table creation.
            SchemaBuilder.CreateTable("GamePartRecord", table => table
                                      .ContentPartRecord()
                                      // UpdateFrom9: adding columns.
                                      .Column <string>("AbstractText")
                                      .Column <DateTime>("GameDate")
                                      .Column <string>("RankingIOSIdentifier")
                                      .Column <string>("RankingAndroidIdentifier")
                                      .Column <int>("MyOrder")
                                      // UpdateFrom10: adding columns.
                                      .Column <bool>("workflowfired")
                                      // UpdateFrom12: adding columns.
                                      .Column <Int32>("QuestionsSortedRandomlyNumber")
                                      .Column <bool>("RandomResponse")
                                      .Column <Decimal>("AnswerPoint")
                                      .Column <Decimal>("AnswerTime")
                                      // UpdateFrom13: adding columns.
                                      .Column <int>("State")
                                      // UpdateFrom16: adding columns.
                                      .Column <String>("GameType")
                                      );


            // UpdateFrom7: table creation.
            SchemaBuilder.CreateTable("RankingPartRecord", table => table
                                      .ContentPartRecord()
                                      .Column <int>("Point")
                                      .Column <string>("Identifier")
                                      .Column <string>("UsernameGameCenter")
                                      .Column <string>("Device")
                                      .Column <int>("ContentIdentifier")
                                      .Column <DateTime>("RegistrationDate")
                                      // UpdateFrom8: adding columns.
                                      .Column <bool>("AccessSecured", col => col.WithDefault(false))
                                      .Column <int>("User_Id")
                                      );


            // UpdateFrom29: table creation.
            SchemaBuilder.CreateTable("UserAnswerInstanceRecord", table => table
                                      .Column <int>("Id", col => col.PrimaryKey().Identity())
                                      .Column <int>("QuestionnairePartRecord_Id")
                                      .Column <int>("User_Id")
                                      // string properties are the same length as those in UserAnswersRecord
                                      // UpdateFrom32: altering columns.
                                      //.Column<string>("SessionID", col => col.WithLength(24))
                                      .Column <string>("SessionID", col => col.WithLength(400))
                                      .Column <string>("Context", col => col.WithLength(255))
                                      .Column <DateTime>("AnswerDate")
                                      .Column <string>("AnswerInstance", col => col.WithLength(64))
                                      );

            // UpdateFrom30: adding indexes.
            SchemaBuilder
            .AlterTable("UserAnswerInstanceRecord", table => table
                        .CreateIndex("IX_LatestAnswersQuery", "QuestionnairePartRecord_Id", "User_Id", "AnswerDate"))
            .AlterTable("UserAnswerInstanceRecord", table => table
                        .CreateIndex("IX_LatestAnswersQuery_WithContext", "QuestionnairePartRecord_Id", "User_Id", "AnswerDate", "Context"));


            SchemaBuilder.CreateForeignKey("UserAnswersAnswer_Answer", "UserAnswersRecord", new string[] { "AnswerRecord_Id" }, "AnswerRecord", new string[] { "Id" });
            SchemaBuilder.CreateForeignKey("UserAnswersQuestion_Question", "UserAnswersRecord", new string[] { "QuestionRecord_Id" }, "QuestionRecord", new string[] { "Id" });


            ContentDefinitionManager.AlterPartDefinition(typeof(QuestionnairePart).Name, cfg => cfg
                                                         .Attachable());


            ContentDefinitionManager.AlterTypeDefinition("Questionnaire", cfg => cfg
                                                         .WithPart(typeof(QuestionnairePart).Name)
                                                         .WithPart("CommonPart")
                                                         .WithPart("LocalizationPart")
                                                         .WithPart("TitlePart")
                                                         .WithPart("BodyPart")
                                                         .WithPart("AutoroutePart")
                                                         .Creatable()
                                                         .Draftable()
                                                         // UpdateFrom22: altering part definition.
                                                         .Listable()
                                                         );


            // UpdateFrom6: altering part definition.
            ContentDefinitionManager.AlterPartDefinition(typeof(GamePart).Name, cfg => cfg
                                                         .Attachable());


            // UpdateFrom7: altering part definition.
            ContentDefinitionManager.AlterTypeDefinition("Ranking", cfg => cfg
                                                         .WithPart(typeof(RankingPart).Name)
                                                         .WithPart("CommonPart")
                                                         );


            // UpdateFrom19: altering part definition.
            ContentDefinitionManager.AlterTypeDefinition("QuestionnaireStatsExport", type => type.WithPart("TitlePart")
                                                         .Draftable(false)
                                                         .Creatable(false));


            // Create function is the complete migration for the module.
            //return 1;
            return(33);
        }