using System; using Microsoft.EntityFrameworkCore.Migrations; namespace IoTSharp.Migrations { public partial class AddDataTable : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Tenant", columns: table => new { Id = table.Column(nullable: false), Name = table.Column(nullable: true), EMail = table.Column(nullable: true), Phone = table.Column(nullable: true), Country = table.Column(nullable: true), Province = table.Column(nullable: true), City = table.Column(nullable: true), Street = table.Column(nullable: true), Address = table.Column(nullable: true), ZipCode = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tenant", x => x.Id); }); migrationBuilder.CreateTable( name: "Customer", columns: table => new { Id = table.Column(nullable: false), Name = table.Column(nullable: true), Email = table.Column(nullable: true), Phone = table.Column(nullable: true), Country = table.Column(nullable: true), Province = table.Column(nullable: true), City = table.Column(nullable: true), Street = table.Column(nullable: true), Address = table.Column(nullable: true), ZipCode = table.Column(nullable: false), TenantId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Customer", x => x.Id); table.ForeignKey( name: "FK_Customer_Tenant_TenantId", column: x => x.TenantId, principalTable: "Tenant", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Device", columns: table => new { Id = table.Column(nullable: false), Name = table.Column(nullable: true), Type = table.Column(nullable: true), TenantId = table.Column(nullable: true), CustomerId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Device", x => x.Id); table.ForeignKey( name: "FK_Device_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Device_Tenant_TenantId", column: x => x.TenantId, principalTable: "Tenant", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Relationship", columns: table => new { Id = table.Column(nullable: false), IdentityId = table.Column(nullable: true), TenantId = table.Column(nullable: true), CustomerId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Relationship", x => x.Id); table.ForeignKey( name: "FK_Relationship_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Relationship_AspNetUsers_IdentityId", column: x => x.IdentityId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Relationship_Tenant_TenantId", column: x => x.TenantId, principalTable: "Tenant", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "AttributeData", columns: table => new { Id = table.Column(nullable: false), KeyName = table.Column(nullable: false), DeviceId1 = table.Column(nullable: false), Type = table.Column(nullable: false), DateTime = table.Column(nullable: false), Value_Boolean = table.Column(nullable: false), Value_String = table.Column(nullable: true), Value_Long = table.Column(nullable: false), Value_Double = table.Column(nullable: false), Value_Json = table.Column(type: "jsonb", nullable: true), Value_XML = table.Column(type: "xml", nullable: true), Value_Binary = table.Column(nullable: true), Discriminator = table.Column(nullable: false), DeviceId = table.Column(nullable: true), TelemetryData_DeviceId = table.Column(nullable: true), TelemetryLatest_DeviceId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_AttributeData", x => x.Id); table.ForeignKey( name: "FK_AttributeData_Device_DeviceId1", column: x => x.DeviceId1, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AttributeData_Device_DeviceId", column: x => x.DeviceId, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_AttributeData_Device_TelemetryData_DeviceId", column: x => x.TelemetryData_DeviceId, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_AttributeData_Device_TelemetryLatest_DeviceId", column: x => x.TelemetryLatest_DeviceId, principalTable: "Device", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_AttributeData_DeviceId1", table: "AttributeData", column: "DeviceId1"); migrationBuilder.CreateIndex( name: "IX_AttributeData_DeviceId", table: "AttributeData", column: "DeviceId"); migrationBuilder.CreateIndex( name: "IX_AttributeData_TelemetryData_DeviceId", table: "AttributeData", column: "TelemetryData_DeviceId"); migrationBuilder.CreateIndex( name: "IX_AttributeData_TelemetryLatest_DeviceId", table: "AttributeData", column: "TelemetryLatest_DeviceId"); migrationBuilder.CreateIndex( name: "IX_Customer_TenantId", table: "Customer", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_Device_CustomerId", table: "Device", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Device_TenantId", table: "Device", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_Relationship_CustomerId", table: "Relationship", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Relationship_IdentityId", table: "Relationship", column: "IdentityId"); migrationBuilder.CreateIndex( name: "IX_Relationship_TenantId", table: "Relationship", column: "TenantId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AttributeData"); migrationBuilder.DropTable( name: "Relationship"); migrationBuilder.DropTable( name: "Device"); migrationBuilder.DropTable( name: "Customer"); migrationBuilder.DropTable( name: "Tenant"); } } }