using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace GymLogAI.Persistence.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "exercises", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Description = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), Embedding = table.Column(type: "real[]", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_exercises", x => x.Id); }); migrationBuilder.CreateTable( name: "users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TelegramUserId = table.Column(type: "bigint", nullable: false), Username = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), FirstName = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), LastName = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_users", x => x.Id); }); migrationBuilder.CreateTable( name: "telegram_messages", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), TelegramChatId = table.Column(type: "bigint", nullable: false), TelegramMessageId = table.Column(type: "integer", nullable: false), Text = table.Column(type: "character varying(4000)", maxLength: 4000, nullable: false), SentAtUtc = table.Column(type: "timestamp with time zone", nullable: false), ImportedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), ParsingStatus = table.Column(type: "integer", nullable: false), ParsingError = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), WorkoutId = table.Column(type: "uuid", nullable: true), ParsedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_telegram_messages", x => x.Id); table.ForeignKey( name: "FK_telegram_messages_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "workouts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), SourceTelegramMessageId = table.Column(type: "uuid", nullable: true), PerformedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), Title = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Notes = table.Column(type: "character varying(4000)", maxLength: 4000, nullable: true), SourceType = table.Column(type: "integer", nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_workouts", x => x.Id); table.ForeignKey( name: "FK_workouts_telegram_messages_SourceTelegramMessageId", column: x => x.SourceTelegramMessageId, principalTable: "telegram_messages", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_workouts_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "workout_exercises", columns: table => new { Id = table.Column(type: "uuid", nullable: false), WorkoutId = table.Column(type: "uuid", nullable: false), ExerciseId = table.Column(type: "uuid", nullable: false), Order = table.Column(type: "integer", nullable: false), Notes = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true) }, constraints: table => { table.PrimaryKey("PK_workout_exercises", x => x.Id); table.ForeignKey( name: "FK_workout_exercises_exercises_ExerciseId", column: x => x.ExerciseId, principalTable: "exercises", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_workout_exercises_workouts_WorkoutId", column: x => x.WorkoutId, principalTable: "workouts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "exercise_sets", columns: table => new { Id = table.Column(type: "uuid", nullable: false), WorkoutExerciseId = table.Column(type: "uuid", nullable: false), Order = table.Column(type: "integer", nullable: false), WeightKg = table.Column(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true), Repetitions = table.Column(type: "integer", nullable: true), DurationSeconds = table.Column(type: "integer", nullable: true), DistanceMeters = table.Column(type: "numeric(10,2)", precision: 10, scale: 2, nullable: true), Notes = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true) }, constraints: table => { table.PrimaryKey("PK_exercise_sets", x => x.Id); table.ForeignKey( name: "FK_exercise_sets_workout_exercises_WorkoutExerciseId", column: x => x.WorkoutExerciseId, principalTable: "workout_exercises", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_exercise_sets_WorkoutExerciseId_Order", table: "exercise_sets", columns: new[] { "WorkoutExerciseId", "Order" }, unique: true); migrationBuilder.CreateIndex( name: "IX_exercises_Name", table: "exercises", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_telegram_messages_TelegramChatId_TelegramMessageId", table: "telegram_messages", columns: new[] { "TelegramChatId", "TelegramMessageId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_telegram_messages_UserId_ParsingStatus", table: "telegram_messages", columns: new[] { "UserId", "ParsingStatus" }); migrationBuilder.CreateIndex( name: "IX_users_TelegramUserId", table: "users", column: "TelegramUserId", unique: true); migrationBuilder.CreateIndex( name: "IX_workout_exercises_ExerciseId", table: "workout_exercises", column: "ExerciseId"); migrationBuilder.CreateIndex( name: "IX_workout_exercises_WorkoutId_Order", table: "workout_exercises", columns: new[] { "WorkoutId", "Order" }, unique: true); migrationBuilder.CreateIndex( name: "IX_workouts_SourceTelegramMessageId", table: "workouts", column: "SourceTelegramMessageId", unique: true); migrationBuilder.CreateIndex( name: "IX_workouts_UserId_PerformedAtUtc", table: "workouts", columns: new[] { "UserId", "PerformedAtUtc" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "exercise_sets"); migrationBuilder.DropTable( name: "workout_exercises"); migrationBuilder.DropTable( name: "exercises"); migrationBuilder.DropTable( name: "workouts"); migrationBuilder.DropTable( name: "telegram_messages"); migrationBuilder.DropTable( name: "users"); } } }