228 lines
11 KiB
C#
228 lines
11 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace GymLogAI.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "exercises",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
Embedding = table.Column<float[]>(type: "real[]", nullable: true),
|
|
CreatedAtUtc = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
|
|
TelegramUserId = table.Column<long>(type: "bigint", nullable: false),
|
|
Username = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
FirstName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
LastName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
CreatedAtUtc = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
TelegramChatId = table.Column<long>(type: "bigint", nullable: false),
|
|
TelegramMessageId = table.Column<int>(type: "integer", nullable: false),
|
|
Text = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: false),
|
|
SentAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
ImportedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
ParsingStatus = table.Column<int>(type: "integer", nullable: false),
|
|
ParsingError = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
WorkoutId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
ParsedAtUtc = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
SourceTelegramMessageId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
PerformedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
Notes = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: true),
|
|
SourceType = table.Column<int>(type: "integer", nullable: false),
|
|
CreatedAtUtc = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
|
|
WorkoutId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
ExerciseId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Order = table.Column<int>(type: "integer", nullable: false),
|
|
Notes = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
|
|
WorkoutExerciseId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Order = table.Column<int>(type: "integer", nullable: false),
|
|
WeightKg = table.Column<decimal>(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true),
|
|
Repetitions = table.Column<int>(type: "integer", nullable: true),
|
|
DurationSeconds = table.Column<int>(type: "integer", nullable: true),
|
|
DistanceMeters = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: true),
|
|
Notes = table.Column<string>(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" });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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");
|
|
}
|
|
}
|
|
}
|