101 lines
4.4 KiB
C#
101 lines
4.4 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace VigilCareRecordsAPI.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddCoverSheets : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "cover_sheets",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
code = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
patient_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
batch_type = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
|
track = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
assign_to_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
generated_by_user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
is_used = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
batch_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
|
used_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_cover_sheets", x => x.id);
|
|
table.ForeignKey(
|
|
name: "FK_cover_sheets_digitization_batches_batch_id",
|
|
column: x => x.batch_id,
|
|
principalTable: "digitization_batches",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_cover_sheets_patients_patient_id",
|
|
column: x => x.patient_id,
|
|
principalSchema: "clinical",
|
|
principalTable: "patients",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_cover_sheets_users_assign_to_user_id",
|
|
column: x => x.assign_to_user_id,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_cover_sheets_users_generated_by_user_id",
|
|
column: x => x.generated_by_user_id,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_cover_sheets_assign_to_user_id",
|
|
table: "cover_sheets",
|
|
column: "assign_to_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_cover_sheets_batch_id",
|
|
table: "cover_sheets",
|
|
column: "batch_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_cover_sheets_code",
|
|
table: "cover_sheets",
|
|
column: "code",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_cover_sheets_generated_by_user_id",
|
|
table: "cover_sheets",
|
|
column: "generated_by_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_cover_sheets_patient_id",
|
|
table: "cover_sheets",
|
|
column: "patient_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_cover_sheets_unused",
|
|
table: "cover_sheets",
|
|
columns: new[] { "is_used", "created_at" },
|
|
filter: "is_used = false");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "cover_sheets");
|
|
}
|
|
}
|
|
}
|