Add EntityFramework code first database migrations

This commit is contained in:
jvyden 2021-10-18 22:35:23 -04:00
parent 36d6255a72
commit ccaebbf9fc
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
15 changed files with 946 additions and 151 deletions

12
.config/dotnet-tools.json Normal file
View file

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "5.0.11",
"commands": [
"dotnet-ef"
]
}
}
}

View file

@ -1,30 +0,0 @@
create table Users
(
UserId int auto_increment,
Username tinytext not null,
IconHash text null,
Game int default 0 not null,
Lists int default 0 not null,
HeartCount int default 0 not null,
YayHash text null,
BooHash text null,
Biography text null,
ReviewCount int default 0 not null,
CommentCount int default 0 not null,
PhotosByMeCount int default 0 not null,
PhotosWithMeCount int default 0 not null,
CommentsEnabled tinyint(1) default 1 not null,
FavouriteSlotCount int default 0 not null,
FavouriteUserCount int default 0 not null,
lolcatftwCount int default 0 not null,
Pins text not null,
StaffChallengeGoldCount int default 0 not null,
StaffChallengeSilverCount int default 0 not null,
StaffChallengeBronzeCount int default 0 not null,
UsedSlots int default 0 not null,
constraint users_user_id_uindex
unique (UserId)
);
alter table Users
add primary key (UserId);

View file

@ -1,22 +0,0 @@
create table Locations
(
Id int not null,
X int not null,
Y int not null
);
create unique index Locations_UserId_uindex
on Locations (Id);
alter table Locations
add constraint Locations_pk
primary key (Id);
alter table Users
add LocationId int null;
alter table Locations
modify Id int auto_increment;

View file

@ -1,37 +0,0 @@
create table Slots
(
SlotId int,
CreatorId int not null,
Name text not null,
Description text not null,
IconHash text not null,
RootLevel text not null,
Resource text not null,
LocationId int not null,
InitiallyLocked bool default false not null,
SubLevel bool default false null,
Lbp1Only bool default false not null,
Shareable int default 0 not null,
AuthorLabels text not null,
BackgroundHash text not null,
MinimumPlayers int default 1 not null,
MaximumPlayers int default 4 not null,
MoveRequired bool default false null
);
create unique index Slots_SlotId_uindex
on Slots (SlotId);
alter table Slots
add constraint Slots_pk
primary key (SlotId);
alter table Slots
modify SlotId int auto_increment;
alter table Slots
alter column CreatorId set default -1;
alter table Slots
modify CreatorId int not null after LocationId;

View file

@ -1,20 +0,0 @@
create table Comments
(
CommentId int,
PosterUserId int not null,
TargetUserId int not null,
Timestamp bigint not null,
ThumbsUp int default 0 not null,
ThumbsDown int default 0 not null,
Message longtext not null
);
create unique index Comments_CommentId_uindex
on Comments (CommentId);
alter table Comments
add constraint Comments_pk
primary key (CommentId);
alter table Comments
modify CommentId int auto_increment;

View file

@ -1,16 +0,0 @@
create table Tokens
(
TokenId int,
UserId int not null,
UserToken text not null
);
create unique index Tokens_TokenId_uindex
on Tokens (TokenId);
alter table Tokens
add constraint Tokens_pk
primary key (TokenId);
alter table Tokens
modify TokenId int auto_increment;

View file

@ -1 +0,0 @@
ALTER TABLE Slots MODIFY AuthorLabels TEXT NULL;

View file

@ -1 +0,0 @@
ALTER TABLE Users ADD COLUMN PlanetHash text not null;

View file

@ -1,17 +0,0 @@
create table QueuedLevels
(
QueuedLevelId int,
UserId int not null,
SlotId int not null
);
create unique index QueuedLevels_QueuedLevelId_uindex
on QueuedLevels (QueuedLevelId);
alter table QueuedLevels
add constraint QueuedLevels_pk
primary key (QueuedLevelId);
alter table QueuedLevels
modify QueuedLevelId int auto_increment;

View file

@ -0,0 +1,324 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ProjectLighthouse;
namespace ProjectLighthouse.Migrations
{
[DbContext(typeof(Database))]
[Migration("20211019021627_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 64)
.HasAnnotation("ProductVersion", "5.0.11");
modelBuilder.Entity("ProjectLighthouse.Types.Comment", b =>
{
b.Property<int>("CommentId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Message")
.HasColumnType("longtext");
b.Property<int>("PosterUserId")
.HasColumnType("int");
b.Property<int>("TargetUserId")
.HasColumnType("int");
b.Property<int>("ThumbsDown")
.HasColumnType("int");
b.Property<int>("ThumbsUp")
.HasColumnType("int");
b.Property<long>("Timestamp")
.HasColumnType("bigint");
b.HasKey("CommentId");
b.HasIndex("PosterUserId");
b.HasIndex("TargetUserId");
b.ToTable("Comments");
});
modelBuilder.Entity("ProjectLighthouse.Types.Location", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("X")
.HasColumnType("int");
b.Property<int>("Y")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Locations");
});
modelBuilder.Entity("ProjectLighthouse.Types.QueuedLevel", b =>
{
b.Property<int>("QueuedLevelId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("SlotId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("QueuedLevelId");
b.HasIndex("SlotId");
b.HasIndex("UserId");
b.ToTable("QueuedLevels");
});
modelBuilder.Entity("ProjectLighthouse.Types.Slot", b =>
{
b.Property<int>("SlotId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("AuthorLabels")
.HasColumnType("longtext");
b.Property<string>("BackgroundHash")
.HasColumnType("longtext");
b.Property<int>("CreatorId")
.HasColumnType("int");
b.Property<string>("Description")
.HasColumnType("longtext");
b.Property<string>("IconHash")
.HasColumnType("longtext");
b.Property<bool>("InitiallyLocked")
.HasColumnType("tinyint(1)");
b.Property<bool>("Lbp1Only")
.HasColumnType("tinyint(1)");
b.Property<int>("LocationId")
.HasColumnType("int");
b.Property<int>("MaximumPlayers")
.HasColumnType("int");
b.Property<int>("MinimumPlayers")
.HasColumnType("int");
b.Property<bool>("MoveRequired")
.HasColumnType("tinyint(1)");
b.Property<string>("Name")
.HasColumnType("longtext");
b.Property<string>("Resource")
.HasColumnType("longtext");
b.Property<string>("RootLevel")
.HasColumnType("longtext");
b.Property<int>("Shareable")
.HasColumnType("int");
b.Property<bool>("SubLevel")
.HasColumnType("tinyint(1)");
b.HasKey("SlotId");
b.HasIndex("CreatorId");
b.HasIndex("LocationId");
b.ToTable("Slots");
});
modelBuilder.Entity("ProjectLighthouse.Types.Token", b =>
{
b.Property<int>("TokenId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<string>("UserToken")
.HasColumnType("longtext");
b.HasKey("TokenId");
b.ToTable("Tokens");
});
modelBuilder.Entity("ProjectLighthouse.Types.User", b =>
{
b.Property<int>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Biography")
.HasColumnType("longtext");
b.Property<string>("BooHash")
.HasColumnType("longtext");
b.Property<int>("CommentCount")
.HasColumnType("int");
b.Property<bool>("CommentsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("FavouriteSlotCount")
.HasColumnType("int");
b.Property<int>("FavouriteUserCount")
.HasColumnType("int");
b.Property<int>("Game")
.HasColumnType("int");
b.Property<int>("HeartCount")
.HasColumnType("int");
b.Property<string>("IconHash")
.HasColumnType("longtext");
b.Property<int>("Lists")
.HasColumnType("int");
b.Property<int>("LocationId")
.HasColumnType("int");
b.Property<int>("LolCatFtwCount")
.HasColumnType("int");
b.Property<int>("PhotosByMeCount")
.HasColumnType("int");
b.Property<int>("PhotosWithMeCount")
.HasColumnType("int");
b.Property<string>("Pins")
.HasColumnType("longtext");
b.Property<string>("PlanetHash")
.HasColumnType("longtext");
b.Property<int>("ReviewCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeBronzeCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeGoldCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeSilverCount")
.HasColumnType("int");
b.Property<int>("UsedSlots")
.HasColumnType("int");
b.Property<string>("Username")
.HasColumnType("longtext");
b.Property<string>("YayHash")
.HasColumnType("longtext");
b.HasKey("UserId");
b.HasIndex("LocationId");
b.ToTable("Users");
});
modelBuilder.Entity("ProjectLighthouse.Types.Comment", b =>
{
b.HasOne("ProjectLighthouse.Types.User", "Poster")
.WithMany()
.HasForeignKey("PosterUserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.User", "Target")
.WithMany()
.HasForeignKey("TargetUserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Poster");
b.Navigation("Target");
});
modelBuilder.Entity("ProjectLighthouse.Types.QueuedLevel", b =>
{
b.HasOne("ProjectLighthouse.Types.Slot", "Slot")
.WithMany()
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Slot");
b.Navigation("User");
});
modelBuilder.Entity("ProjectLighthouse.Types.Slot", b =>
{
b.HasOne("ProjectLighthouse.Types.User", "Creator")
.WithMany()
.HasForeignKey("CreatorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.Location", "Location")
.WithMany()
.HasForeignKey("LocationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Creator");
b.Navigation("Location");
});
modelBuilder.Entity("ProjectLighthouse.Types.User", b =>
{
b.HasOne("ProjectLighthouse.Types.Location", "Location")
.WithMany()
.HasForeignKey("LocationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Location");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,257 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ProjectLighthouse.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Locations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
X = table.Column<int>(type: "int", nullable: false),
Y = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Locations", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Tokens",
columns: table => new
{
TokenId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
UserToken = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_Tokens", x => x.TokenId);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
UserId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Username = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IconHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Game = table.Column<int>(type: "int", nullable: false),
Lists = table.Column<int>(type: "int", nullable: false),
HeartCount = table.Column<int>(type: "int", nullable: false),
YayHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
BooHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Biography = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ReviewCount = table.Column<int>(type: "int", nullable: false),
CommentCount = table.Column<int>(type: "int", nullable: false),
PhotosByMeCount = table.Column<int>(type: "int", nullable: false),
PhotosWithMeCount = table.Column<int>(type: "int", nullable: false),
CommentsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
LocationId = table.Column<int>(type: "int", nullable: false),
FavouriteSlotCount = table.Column<int>(type: "int", nullable: false),
FavouriteUserCount = table.Column<int>(type: "int", nullable: false),
LolCatFtwCount = table.Column<int>(type: "int", nullable: false),
Pins = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
StaffChallengeGoldCount = table.Column<int>(type: "int", nullable: false),
StaffChallengeSilverCount = table.Column<int>(type: "int", nullable: false),
StaffChallengeBronzeCount = table.Column<int>(type: "int", nullable: false),
PlanetHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
UsedSlots = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.UserId);
table.ForeignKey(
name: "FK_Users_Locations_LocationId",
column: x => x.LocationId,
principalTable: "Locations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Comments",
columns: table => new
{
CommentId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
PosterUserId = table.Column<int>(type: "int", nullable: false),
TargetUserId = table.Column<int>(type: "int", nullable: false),
Timestamp = table.Column<long>(type: "bigint", nullable: false),
Message = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ThumbsUp = table.Column<int>(type: "int", nullable: false),
ThumbsDown = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Comments", x => x.CommentId);
table.ForeignKey(
name: "FK_Comments_Users_PosterUserId",
column: x => x.PosterUserId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Comments_Users_TargetUserId",
column: x => x.TargetUserId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Slots",
columns: table => new
{
SlotId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IconHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
RootLevel = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Resource = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LocationId = table.Column<int>(type: "int", nullable: false),
CreatorId = table.Column<int>(type: "int", nullable: false),
InitiallyLocked = table.Column<bool>(type: "tinyint(1)", nullable: false),
SubLevel = table.Column<bool>(type: "tinyint(1)", nullable: false),
Lbp1Only = table.Column<bool>(type: "tinyint(1)", nullable: false),
Shareable = table.Column<int>(type: "int", nullable: false),
AuthorLabels = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
BackgroundHash = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
MinimumPlayers = table.Column<int>(type: "int", nullable: false),
MaximumPlayers = table.Column<int>(type: "int", nullable: false),
MoveRequired = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Slots", x => x.SlotId);
table.ForeignKey(
name: "FK_Slots_Locations_LocationId",
column: x => x.LocationId,
principalTable: "Locations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Slots_Users_CreatorId",
column: x => x.CreatorId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "QueuedLevels",
columns: table => new
{
QueuedLevelId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
SlotId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_QueuedLevels", x => x.QueuedLevelId);
table.ForeignKey(
name: "FK_QueuedLevels_Slots_SlotId",
column: x => x.SlotId,
principalTable: "Slots",
principalColumn: "SlotId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_QueuedLevels_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Comments_PosterUserId",
table: "Comments",
column: "PosterUserId");
migrationBuilder.CreateIndex(
name: "IX_Comments_TargetUserId",
table: "Comments",
column: "TargetUserId");
migrationBuilder.CreateIndex(
name: "IX_QueuedLevels_SlotId",
table: "QueuedLevels",
column: "SlotId");
migrationBuilder.CreateIndex(
name: "IX_QueuedLevels_UserId",
table: "QueuedLevels",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Slots_CreatorId",
table: "Slots",
column: "CreatorId");
migrationBuilder.CreateIndex(
name: "IX_Slots_LocationId",
table: "Slots",
column: "LocationId");
migrationBuilder.CreateIndex(
name: "IX_Users_LocationId",
table: "Users",
column: "LocationId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Comments");
migrationBuilder.DropTable(
name: "QueuedLevels");
migrationBuilder.DropTable(
name: "Tokens");
migrationBuilder.DropTable(
name: "Slots");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Locations");
}
}
}

View file

@ -0,0 +1,322 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ProjectLighthouse;
namespace ProjectLighthouse.Migrations
{
[DbContext(typeof(Database))]
partial class DatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 64)
.HasAnnotation("ProductVersion", "5.0.11");
modelBuilder.Entity("ProjectLighthouse.Types.Comment", b =>
{
b.Property<int>("CommentId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Message")
.HasColumnType("longtext");
b.Property<int>("PosterUserId")
.HasColumnType("int");
b.Property<int>("TargetUserId")
.HasColumnType("int");
b.Property<int>("ThumbsDown")
.HasColumnType("int");
b.Property<int>("ThumbsUp")
.HasColumnType("int");
b.Property<long>("Timestamp")
.HasColumnType("bigint");
b.HasKey("CommentId");
b.HasIndex("PosterUserId");
b.HasIndex("TargetUserId");
b.ToTable("Comments");
});
modelBuilder.Entity("ProjectLighthouse.Types.Location", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("X")
.HasColumnType("int");
b.Property<int>("Y")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Locations");
});
modelBuilder.Entity("ProjectLighthouse.Types.QueuedLevel", b =>
{
b.Property<int>("QueuedLevelId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("SlotId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("QueuedLevelId");
b.HasIndex("SlotId");
b.HasIndex("UserId");
b.ToTable("QueuedLevels");
});
modelBuilder.Entity("ProjectLighthouse.Types.Slot", b =>
{
b.Property<int>("SlotId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("AuthorLabels")
.HasColumnType("longtext");
b.Property<string>("BackgroundHash")
.HasColumnType("longtext");
b.Property<int>("CreatorId")
.HasColumnType("int");
b.Property<string>("Description")
.HasColumnType("longtext");
b.Property<string>("IconHash")
.HasColumnType("longtext");
b.Property<bool>("InitiallyLocked")
.HasColumnType("tinyint(1)");
b.Property<bool>("Lbp1Only")
.HasColumnType("tinyint(1)");
b.Property<int>("LocationId")
.HasColumnType("int");
b.Property<int>("MaximumPlayers")
.HasColumnType("int");
b.Property<int>("MinimumPlayers")
.HasColumnType("int");
b.Property<bool>("MoveRequired")
.HasColumnType("tinyint(1)");
b.Property<string>("Name")
.HasColumnType("longtext");
b.Property<string>("Resource")
.HasColumnType("longtext");
b.Property<string>("RootLevel")
.HasColumnType("longtext");
b.Property<int>("Shareable")
.HasColumnType("int");
b.Property<bool>("SubLevel")
.HasColumnType("tinyint(1)");
b.HasKey("SlotId");
b.HasIndex("CreatorId");
b.HasIndex("LocationId");
b.ToTable("Slots");
});
modelBuilder.Entity("ProjectLighthouse.Types.Token", b =>
{
b.Property<int>("TokenId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<string>("UserToken")
.HasColumnType("longtext");
b.HasKey("TokenId");
b.ToTable("Tokens");
});
modelBuilder.Entity("ProjectLighthouse.Types.User", b =>
{
b.Property<int>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Biography")
.HasColumnType("longtext");
b.Property<string>("BooHash")
.HasColumnType("longtext");
b.Property<int>("CommentCount")
.HasColumnType("int");
b.Property<bool>("CommentsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("FavouriteSlotCount")
.HasColumnType("int");
b.Property<int>("FavouriteUserCount")
.HasColumnType("int");
b.Property<int>("Game")
.HasColumnType("int");
b.Property<int>("HeartCount")
.HasColumnType("int");
b.Property<string>("IconHash")
.HasColumnType("longtext");
b.Property<int>("Lists")
.HasColumnType("int");
b.Property<int>("LocationId")
.HasColumnType("int");
b.Property<int>("LolCatFtwCount")
.HasColumnType("int");
b.Property<int>("PhotosByMeCount")
.HasColumnType("int");
b.Property<int>("PhotosWithMeCount")
.HasColumnType("int");
b.Property<string>("Pins")
.HasColumnType("longtext");
b.Property<string>("PlanetHash")
.HasColumnType("longtext");
b.Property<int>("ReviewCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeBronzeCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeGoldCount")
.HasColumnType("int");
b.Property<int>("StaffChallengeSilverCount")
.HasColumnType("int");
b.Property<int>("UsedSlots")
.HasColumnType("int");
b.Property<string>("Username")
.HasColumnType("longtext");
b.Property<string>("YayHash")
.HasColumnType("longtext");
b.HasKey("UserId");
b.HasIndex("LocationId");
b.ToTable("Users");
});
modelBuilder.Entity("ProjectLighthouse.Types.Comment", b =>
{
b.HasOne("ProjectLighthouse.Types.User", "Poster")
.WithMany()
.HasForeignKey("PosterUserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.User", "Target")
.WithMany()
.HasForeignKey("TargetUserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Poster");
b.Navigation("Target");
});
modelBuilder.Entity("ProjectLighthouse.Types.QueuedLevel", b =>
{
b.HasOne("ProjectLighthouse.Types.Slot", "Slot")
.WithMany()
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Slot");
b.Navigation("User");
});
modelBuilder.Entity("ProjectLighthouse.Types.Slot", b =>
{
b.HasOne("ProjectLighthouse.Types.User", "Creator")
.WithMany()
.HasForeignKey("CreatorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ProjectLighthouse.Types.Location", "Location")
.WithMany()
.HasForeignKey("LocationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Creator");
b.Navigation("Location");
});
modelBuilder.Entity("ProjectLighthouse.Types.User", b =>
{
b.HasOne("ProjectLighthouse.Types.Location", "Location")
.WithMany()
.HasForeignKey("LocationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Location");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ProjectLighthouse.Types;
@ -9,7 +8,16 @@ namespace ProjectLighthouse {
public static class Program {
public static void Main(string[] args) {
Console.WriteLine("Welcome to Project Lighthouse!");
Console.WriteLine(ServerSettings.DbConnected ? "Connected to the database." : "Database unavailable. Starting in stateless mode.");
bool dbConnected = ServerSettings.DbConnected;
Console.WriteLine(dbConnected ? "Connected to the database." : "Database unavailable. Exiting.");
if(dbConnected) {
Console.WriteLine("Migrating database...");
new Database().Database.Migrate();
}
else {
Environment.Exit(1);
}
CreateHostBuilder(args).Build().Run();
}

View file

@ -9,6 +9,10 @@
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
</ItemGroup>

View file

@ -17,11 +17,12 @@ This will be written when we're out of beta. Consider this your barrier to entry
Lighthouse requires a MySQL database at this time.
For Linux users running docker, one can be set up using the `docker-compose.yml` file in the root of the project folder.
Once you've gotten MySQL running you can create the schema by running all of the `.sql` files in the `DatabaseMigrations` folder against the database.
Next, make sure the `LIGHTHOUSE_DB_CONNECTION_STRING` environment variable is set correctly.
By default it is `server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse`. If you are running the database via
the above `docker-compose.yml` you shouldn't need to change this. For other development/especially production environments
you will need to change this.
Then, you can finally run Lighthouse. It will connect using a connection string stored in `LIGHTHOUSE_DB_CONNECTION_STRING` by default.
The connection string is `server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse` by default. You can modify it if you'd like to,
but you shouldn't need to if you're using docker since the docker-compose file matches this by default.
Once you've gotten MySQL running you can run Lighthouse. It will take care of the rest.
## Connecting
@ -47,4 +48,15 @@ To launch the game with the patched EBOOT, open up RPCS3, go to File, Boot SELF/
Assuming you are running the patched version of RPCS3, you patched the file correctly, the database is migrated, and Lighthouse is running, the game should now connect.
Take a break.
Take a break.
## Contributing Tips
### Database
Some modifications may require updates to the database schema. You can automatically create a migration file by:
1. Making sure the tools are installed. You can do this by running `dotnet tool restore`.
2. Making sure `LIGHTHOUSE_DB_CONNECTION_STRING is set correctly`.
3. Making your changes to the database. I wont cover this since if you're making database changes you should know what you're doing.
4. Running `dotnet ef migrations add <NameOfMigrationInPascalCase>`.