Skip to content

Commit

Permalink
Downgrade .Net 9 to .Net 8 due to dependency Pomelo.EntityFrameworkCo…
Browse files Browse the repository at this point in the history
…re.MySql isnt updated to .Net 9 RC (or greater)
  • Loading branch information
carvalholuigi25 committed Oct 4, 2024
1 parent 2d30d37 commit 36b0a68
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 27 deletions.
Binary file modified server/api/LCPMobileAppApi/Database/sqlite/lcpmaapidb.db
Binary file not shown.
28 changes: 14 additions & 14 deletions server/api/LCPMobileAppApi/LCPMobileAppApi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -19,27 +19,27 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="System.Text.Json" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0-rc.1.24452.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="MySql.Data" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0-rc.1.24451.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0-rc.1.24451.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0-rc.1.24451.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0-rc.1.24451.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0-rc.1.24451.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-rc.1.24451.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0-rc.1.24457.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.5" />
<PackageReference Include="NSwag.AspNetCore" Version="14.1.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions server/api/LCPMobileAppApi/Scripts/bash/gendb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ chkDNEFInstalled() {
addDB() {
chkDNEFInstalled

if [ -d "$pthmig" ]; then
rm -rf "$pthmig"
if [ -d "$pthmig/$1" ]; then
rm -rf "$pthmig/$1"
fi

if [ -d "$pthproj/Database/$1" ]; then
Expand Down
14 changes: 7 additions & 7 deletions server/api/LCPMobileAppApi/Scripts/batch/gendb.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ goto :endalt
:addDB
call :chkDNEFInstalled

if exist "%pthmig%" (
rmdir /s /q "%pthmig%"
if exist "%pthmig%\%~1" (
rmdir /s /q "%pthmig%\%~1"
)

if exist "%pthproj%\Database\%~1" (
Expand All @@ -37,35 +37,35 @@ dotnet ef database drop --force --context "MDBContext%~1"
dotnet ef migrations add "InitialCreate%~1" --context "MDBContext%~1" --output-dir "%pthmig%/%~1"
dotnet ef database update "InitialCreate%~1" --context "MDBContext%~1"
dotnet ef migrations script --context "MDBContext%~1" --output "Scripts/sql/migscr%~1.sql"
goto :end
goto :endalt

:addSQLite
cls
SET DefDBMode=SQLite
echo %DefDBMode%
call :addDB %DefDBMode%
goto :end
goto :endalt

:addSQLServer
cls
SET DefDBMode=SQLServer
echo %DefDBMode%
call :addDB %DefDBMode%
goto :end
goto :endalt

:addPostgresSQL
cls
SET DefDBMode=PostgresSQL
echo %DefDBMode%
call :addDB %DefDBMode%
goto :end
goto :endalt

:addMySQL
cls
SET DefDBMode=MySQL
echo %DefDBMode%
call :addDB %DefDBMode%
goto :end
goto :endalt

:addAll
call :addSQLite
Expand Down
42 changes: 42 additions & 0 deletions server/api/LCPMobileAppApi/Scripts/sql/migscrMySQL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
CREATE TABLE IF NOT EXISTS `__EFMigrationsHistory` (
`MigrationId` varchar(150) CHARACTER SET utf8mb4 NOT NULL,
`ProductVersion` varchar(32) CHARACTER SET utf8mb4 NOT NULL,
CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`)
) CHARACTER SET=utf8mb4;

START TRANSACTION;

ALTER DATABASE CHARACTER SET utf8mb4;

CREATE TABLE `Users` (
`Id` int NOT NULL AUTO_INCREMENT,
`Username` longtext CHARACTER SET utf8mb4 NOT NULL,
`Password` longtext CHARACTER SET utf8mb4 NOT NULL,
`FirstName` longtext CHARACTER SET utf8mb4 NULL,
`LastName` longtext CHARACTER SET utf8mb4 NULL,
`Role` int NULL,
CONSTRAINT `PK_Users` PRIMARY KEY (`Id`)
) CHARACTER SET=utf8mb4;

CREATE TABLE `RefreshToken` (
`Id` int NOT NULL AUTO_INCREMENT,
`Token` longtext CHARACTER SET utf8mb4 NOT NULL,
`Expires` datetime NOT NULL,
`Created` datetime NOT NULL,
`CreatedByIp` longtext CHARACTER SET utf8mb4 NOT NULL,
`Revoked` datetime NULL,
`RevokedByIp` longtext CHARACTER SET utf8mb4 NOT NULL,
`ReplacedByToken` longtext CHARACTER SET utf8mb4 NOT NULL,
`ReasonRevoked` longtext CHARACTER SET utf8mb4 NOT NULL,
`UserId` int NOT NULL,
CONSTRAINT `PK_RefreshToken` PRIMARY KEY (`Id`),
CONSTRAINT `FK_RefreshToken_Users_UserId` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE CASCADE
) CHARACTER SET=utf8mb4;

CREATE INDEX `IX_RefreshToken_UserId` ON `RefreshToken` (`UserId`);

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('20241004114847_InitialCreateMySQL', '8.0.8');

COMMIT;

40 changes: 40 additions & 0 deletions server/api/LCPMobileAppApi/Scripts/sql/migscrPostgresSQL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);

START TRANSACTION;

CREATE TABLE "Users" (
"Id" integer GENERATED BY DEFAULT AS IDENTITY,
"Username" text NOT NULL,
"Password" text NOT NULL,
"FirstName" text,
"LastName" text,
"Role" integer,
CONSTRAINT "PK_Users" PRIMARY KEY ("Id")
);

CREATE TABLE "RefreshToken" (
"Id" integer GENERATED BY DEFAULT AS IDENTITY,
"Token" text NOT NULL,
"Expires" timestamp with time zone NOT NULL,
"Created" timestamp with time zone NOT NULL,
"CreatedByIp" text NOT NULL,
"Revoked" timestamp with time zone,
"RevokedByIp" text NOT NULL,
"ReplacedByToken" text NOT NULL,
"ReasonRevoked" text NOT NULL,
"UserId" integer NOT NULL,
CONSTRAINT "PK_RefreshToken" PRIMARY KEY ("Id"),
CONSTRAINT "FK_RefreshToken_Users_UserId" FOREIGN KEY ("UserId") REFERENCES "Users" ("Id") ON DELETE CASCADE
);

CREATE INDEX "IX_RefreshToken_UserId" ON "RefreshToken" ("UserId");

INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20241004114813_InitialCreatePostgresSQL', '8.0.8');

COMMIT;

2 changes: 1 addition & 1 deletion server/api/LCPMobileAppApi/Scripts/sql/migscrSQLServer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CREATE INDEX [IX_RefreshToken_UserId] ON [RefreshToken] ([UserId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20241003110508_InitialCreateSQLServer', N'9.0.0-rc.1.24451.1');
VALUES (N'20241004114740_InitialCreateSQLServer', N'8.0.8');
GO

COMMIT;
Expand Down
2 changes: 1 addition & 1 deletion server/api/LCPMobileAppApi/Scripts/sql/migscrSQLite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CREATE TABLE "RefreshToken" (
CREATE INDEX "IX_RefreshToken_UserId" ON "RefreshToken" ("UserId");

INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20241003110412_InitialCreateSQLite', '9.0.0-rc.1.24451.1');
VALUES ('20241004114705_InitialCreateSQLite', '8.0.8');

COMMIT;

2 changes: 1 addition & 1 deletion server/api/LCPMobileAppApi/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"MySQL": "Server=localhost;Port=3306;Database=lcpmaapidb;Uid=root;Pwd=1234",
"PostgresSQL" : "User ID=postgres;Password=1234;Server=localhost;Port=5432;Database=lcpmaapidb"
},
"DefDBMode": "SQLite",
"DefDBMode": "MySQL",
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion server/api/LCPMobileAppApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"MySQL": "Server=localhost;Port=3306;Database=lcpmaapidb;Uid=root;Pwd=1234",
"PostgresSQL" : "User ID=postgres;Password=1234;Server=localhost;Port=5432;Database=lcpmaapidb"
},
"DefDBMode": "SQLite",
"DefDBMode": "MySQL",
"AllowedHosts": "*"
}

1 comment on commit 36b0a68

@carvalholuigi25
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See and read more at:

EF Core 9 support #1841

Please sign in to comment.