using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace SurveyBackend.Infrastructure.Data.Migrations { /// public partial class Initial : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Groups", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Label = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Groups", x => x.Id); }); migrationBuilder.CreateTable( name: "Surveys", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Title = table.Column(type: "TEXT", nullable: false), Description = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Surveys", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Email = table.Column(type: "TEXT", nullable: false), FirstName = table.Column(type: "TEXT", nullable: false), LastName = table.Column(type: "TEXT", nullable: false), Password = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Completions", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), SurveyId = table.Column(type: "INTEGER", nullable: false), FinishedAt = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Completions", x => x.Id); table.ForeignKey( name: "FK_Completions_Surveys_SurveyId", column: x => x.SurveyId, principalTable: "Surveys", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Questions", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), SurveyId = table.Column(type: "INTEGER", nullable: false), Title = table.Column(type: "TEXT", nullable: false), Discriminator = table.Column(type: "TEXT", maxLength: 34, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Questions", x => x.Id); table.ForeignKey( name: "FK_Questions_Surveys_SurveyId", column: x => x.SurveyId, principalTable: "Surveys", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "GroupUser", columns: table => new { GroupsId = table.Column(type: "INTEGER", nullable: false), UsersId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GroupUser", x => new { x.GroupsId, x.UsersId }); table.ForeignKey( name: "FK_GroupUser_Groups_GroupsId", column: x => x.GroupsId, principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GroupUser_Users_UsersId", column: x => x.UsersId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Answers", columns: table => new { CompletionId = table.Column(type: "INTEGER", nullable: false), QuestionId = table.Column(type: "INTEGER", nullable: false), AnswerText = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Answers", x => new { x.CompletionId, x.QuestionId }); table.ForeignKey( name: "FK_Answers_Completions_CompletionId", column: x => x.CompletionId, principalTable: "Completions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Answers_Questions_QuestionId", column: x => x.QuestionId, principalTable: "Questions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AnswerVariant", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), QuestionId = table.Column(type: "INTEGER", nullable: false), Text = table.Column(type: "TEXT", nullable: false), MultipleAnswerQuestionId = table.Column(type: "INTEGER", nullable: true), SingleAnswerQuestionId = table.Column(type: "INTEGER", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AnswerVariant", x => x.Id); table.ForeignKey( name: "FK_AnswerVariant_Questions_MultipleAnswerQuestionId", column: x => x.MultipleAnswerQuestionId, principalTable: "Questions", principalColumn: "Id"); table.ForeignKey( name: "FK_AnswerVariant_Questions_QuestionId", column: x => x.QuestionId, principalTable: "Questions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AnswerVariant_Questions_SingleAnswerQuestionId", column: x => x.SingleAnswerQuestionId, principalTable: "Questions", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_Answers_QuestionId", table: "Answers", column: "QuestionId"); migrationBuilder.CreateIndex( name: "IX_AnswerVariant_MultipleAnswerQuestionId", table: "AnswerVariant", column: "MultipleAnswerQuestionId"); migrationBuilder.CreateIndex( name: "IX_AnswerVariant_QuestionId", table: "AnswerVariant", column: "QuestionId"); migrationBuilder.CreateIndex( name: "IX_AnswerVariant_SingleAnswerQuestionId", table: "AnswerVariant", column: "SingleAnswerQuestionId"); migrationBuilder.CreateIndex( name: "IX_Completions_SurveyId", table: "Completions", column: "SurveyId"); migrationBuilder.CreateIndex( name: "IX_GroupUser_UsersId", table: "GroupUser", column: "UsersId"); migrationBuilder.CreateIndex( name: "IX_Questions_SurveyId", table: "Questions", column: "SurveyId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Answers"); migrationBuilder.DropTable( name: "AnswerVariant"); migrationBuilder.DropTable( name: "GroupUser"); migrationBuilder.DropTable( name: "Completions"); migrationBuilder.DropTable( name: "Questions"); migrationBuilder.DropTable( name: "Groups"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Surveys"); } } }