adding migration for person photo

This commit is contained in:
2025-10-13 22:38:16 +11:00
parent ee19397f59
commit c62ae2cd42
6 changed files with 615 additions and 2 deletions
+6 -1
View File
@@ -2,7 +2,12 @@
using Microsoft.EntityFrameworkCore;
using System.Data.Common;
using FamilyTreeAPI.Entities;
using FamilyTreeAPI.Interface;
/*
dotnet ef migrations add PersonPhoto run at project .csproj folder
dotnet ef database update
*/
namespace FamilyTreeAPI.Models
{
@@ -0,0 +1,229 @@
// <auto-generated />
using System;
using FamilyTreeAPI.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FamilyTreeAPI.Migrations
{
[DbContext(typeof(FamilyTreeDBContext))]
[Migration("20251013112634_PersonPhoto")]
partial class PersonPhoto
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FamilyTreeAPI.Models.Lookup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Code")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("code");
b.Property<string>("Description")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("description");
b.Property<bool?>("Lactive")
.HasColumnType("boolean")
.HasColumnName("lactive");
b.Property<string>("Type")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("ltype");
b.HasKey("Id");
b.ToTable("lookup", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.Person", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.HasMaxLength(120)
.HasColumnType("character varying(120)")
.HasColumnName("address");
b.Property<bool?>("Alive")
.HasColumnType("boolean")
.HasColumnName("alive");
b.Property<string>("Email")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("email");
b.Property<int?>("FatherId")
.HasColumnType("integer")
.HasColumnName("fatherid");
b.Property<string>("FirstName")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("firstname");
b.Property<string>("Image")
.HasMaxLength(300)
.HasColumnType("character varying(300)")
.HasColumnName("image");
b.Property<string>("LastName")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("lastname");
b.Property<int?>("MotherId")
.HasColumnType("integer")
.HasColumnName("motherid");
b.Property<string>("Phone")
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("phone");
b.Property<string>("Sex")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("sex");
b.Property<DateTime?>("dob")
.HasColumnType("timestamp without time zone")
.HasColumnName("dob");
b.HasKey("Id");
b.ToTable("person", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.PersonPhoto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<byte[]>("ImagePhoto")
.IsRequired()
.HasColumnType("bytea")
.HasColumnName("imagephot");
b.Property<int>("PersonId")
.HasColumnType("integer")
.HasColumnName("personid");
b.Property<string>("Photo")
.IsRequired()
.HasColumnType("text")
.HasColumnName("photo");
b.HasKey("Id");
b.ToTable("personphoto", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.RelationShip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("PersonId")
.HasColumnType("integer")
.HasColumnName("personid");
b.Property<int>("RelatePersonId")
.HasColumnType("integer")
.HasColumnName("relatepersonid");
b.HasKey("Id");
b.ToTable("relationship", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.staff", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("email");
b.Property<string>("Firstname")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("firstname");
b.Property<string>("Lastname")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("lastname");
b.Property<string>("Phone")
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("phone");
b.Property<bool?>("Sactive")
.HasColumnType("boolean")
.HasColumnName("sactive");
b.Property<string>("Spassword")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("spassword");
b.Property<int?>("Srole")
.HasColumnType("integer")
.HasColumnName("srole");
b.Property<int?>("Stype")
.HasColumnType("integer")
.HasColumnName("stype");
b.HasKey("Id");
b.ToTable("staff", (string)null);
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,128 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FamilyTreeAPI.Migrations
{
/// <inheritdoc />
public partial class PersonPhoto : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
/*
migrationBuilder.CreateTable(
name: "lookup",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
code = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
description = table.Column<string>(type: "character varying(80)", maxLength: 80, nullable: true),
ltype = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
lactive = table.Column<bool>(type: "boolean", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_lookup", x => x.id);
});
migrationBuilder.CreateTable(
name: "person",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
firstname = table.Column<string>(type: "character varying(70)", maxLength: 70, nullable: true),
lastname = table.Column<string>(type: "character varying(70)", maxLength: 70, nullable: true),
email = table.Column<string>(type: "character varying(80)", maxLength: 80, nullable: true),
phone = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: true),
address = table.Column<string>(type: "character varying(120)", maxLength: 120, nullable: true),
sex = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
image = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
alive = table.Column<bool>(type: "boolean", nullable: true),
motherid = table.Column<int>(type: "integer", nullable: true),
fatherid = table.Column<int>(type: "integer", nullable: true),
dob = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_person", x => x.id);
});
*/
migrationBuilder.CreateTable(
name: "personphoto",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
personid = table.Column<int>(type: "integer", nullable: false),
photo = table.Column<string>(type: "text", nullable: false),
imagephot = table.Column<byte[]>(type: "bytea", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_personphoto", x => x.id);
});
/*
migrationBuilder.CreateTable(
name: "relationship",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
relatepersonid = table.Column<int>(type: "integer", nullable: false),
personid = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_relationship", x => x.id);
});
migrationBuilder.CreateTable(
name: "staff",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
firstname = table.Column<string>(type: "character varying(70)", maxLength: 70, nullable: true),
lastname = table.Column<string>(type: "character varying(70)", maxLength: 70, nullable: true),
email = table.Column<string>(type: "character varying(80)", maxLength: 80, nullable: true),
phone = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: true),
stype = table.Column<int>(type: "integer", nullable: true),
srole = table.Column<int>(type: "integer", nullable: true),
spassword = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
sactive = table.Column<bool>(type: "boolean", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_staff", x => x.id);
});
*/
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
/*
migrationBuilder.DropTable(
name: "lookup");
migrationBuilder.DropTable(
name: "person");
migrationBuilder.DropTable(
name: "relationship");
migrationBuilder.DropTable(
name: "staff");
*/
migrationBuilder.DropTable(
name: "personphoto");
}
}
}
@@ -0,0 +1,226 @@
// <auto-generated />
using System;
using FamilyTreeAPI.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FamilyTreeAPI.Migrations
{
[DbContext(typeof(FamilyTreeDBContext))]
partial class FamilyTreeDBContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FamilyTreeAPI.Models.Lookup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Code")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("code");
b.Property<string>("Description")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("description");
b.Property<bool?>("Lactive")
.HasColumnType("boolean")
.HasColumnName("lactive");
b.Property<string>("Type")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("ltype");
b.HasKey("Id");
b.ToTable("lookup", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.Person", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.HasMaxLength(120)
.HasColumnType("character varying(120)")
.HasColumnName("address");
b.Property<bool?>("Alive")
.HasColumnType("boolean")
.HasColumnName("alive");
b.Property<string>("Email")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("email");
b.Property<int?>("FatherId")
.HasColumnType("integer")
.HasColumnName("fatherid");
b.Property<string>("FirstName")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("firstname");
b.Property<string>("Image")
.HasMaxLength(300)
.HasColumnType("character varying(300)")
.HasColumnName("image");
b.Property<string>("LastName")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("lastname");
b.Property<int?>("MotherId")
.HasColumnType("integer")
.HasColumnName("motherid");
b.Property<string>("Phone")
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("phone");
b.Property<string>("Sex")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("sex");
b.Property<DateTime?>("dob")
.HasColumnType("timestamp without time zone")
.HasColumnName("dob");
b.HasKey("Id");
b.ToTable("person", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.PersonPhoto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<byte[]>("ImagePhoto")
.IsRequired()
.HasColumnType("bytea")
.HasColumnName("imagephot");
b.Property<int>("PersonId")
.HasColumnType("integer")
.HasColumnName("personid");
b.Property<string>("Photo")
.IsRequired()
.HasColumnType("text")
.HasColumnName("photo");
b.HasKey("Id");
b.ToTable("personphoto", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.RelationShip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("PersonId")
.HasColumnType("integer")
.HasColumnName("personid");
b.Property<int>("RelatePersonId")
.HasColumnType("integer")
.HasColumnName("relatepersonid");
b.HasKey("Id");
b.ToTable("relationship", (string)null);
});
modelBuilder.Entity("FamilyTreeAPI.Models.staff", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.HasMaxLength(80)
.HasColumnType("character varying(80)")
.HasColumnName("email");
b.Property<string>("Firstname")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("firstname");
b.Property<string>("Lastname")
.HasMaxLength(70)
.HasColumnType("character varying(70)")
.HasColumnName("lastname");
b.Property<string>("Phone")
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("phone");
b.Property<bool?>("Sactive")
.HasColumnType("boolean")
.HasColumnName("sactive");
b.Property<string>("Spassword")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("spassword");
b.Property<int?>("Srole")
.HasColumnType("integer")
.HasColumnName("srole");
b.Property<int?>("Stype")
.HasColumnType("integer")
.HasColumnName("stype");
b.HasKey("Id");
b.ToTable("staff", (string)null);
});
#pragma warning restore 612, 618
}
}
}
@@ -21,8 +21,8 @@ namespace FamilyTreeAPI.Models
public virtual DbSet<RelationShip> RelationShips { get; set; } = null!;
public virtual DbSet<Lookup> Lookups { get; set; } = null!;
public virtual DbSet<staff> staff { get; set; } = null!;
public virtual DbSet<PersonPhoto> PersonPhotos { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -74,6 +74,18 @@ namespace FamilyTreeAPI.Models
});
modelBuilder.Entity<PersonPhoto>(entity =>
{
entity.ToTable("personphoto");
entity.Property(e => e.Id).HasColumnName("id");
entity.Property(e => e.PersonId).HasColumnName("personid");
entity.Property(e => e.Photo).HasColumnName("photo");
entity.Property(e => e.ImagePhoto).HasColumnName("imagephot"); //try to store binary in table. "bytea"
});
modelBuilder.Entity<Lookup>(entity =>
{
entity.ToTable("lookup");
+13
View File
@@ -0,0 +1,13 @@
namespace FamilyTreeAPI.Models
{
public class PersonPhoto
{
public int Id { get; set; }
public int PersonId { get; set; }
public string Photo { get; set; }
public byte[] ImagePhoto { get; set; }
}
}