mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Update seeds
This commit is contained in:
15
.idea/.idea.biergarten/.idea/.gitignore
generated
vendored
15
.idea/.idea.biergarten/.idea/.gitignore
generated
vendored
@@ -1,15 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.biergarten.iml
|
||||
/contentModel.xml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
1
.idea/.idea.biergarten/.idea/.name
generated
1
.idea/.idea.biergarten/.idea/.name
generated
@@ -1 +0,0 @@
|
||||
biergarten
|
||||
24
.idea/.idea.biergarten/.idea/dataSources.xml
generated
24
.idea/.idea.biergarten/.idea/dataSources.xml
generated
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source
|
||||
source="LOCAL"
|
||||
name="Biergarten@localhost"
|
||||
uuid="7eb1584d-925b-46f8-a3a2-a73152a2d625"
|
||||
>
|
||||
<driver-ref>sqlserver.jb</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.jetbrains.jdbc.sqlserver.SqlServerDriver</jdbc-driver>
|
||||
<jdbc-url>Server=localhost;Database=Biergarten;TrustServerCertificate=True;</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property
|
||||
name="com.intellij.clouds.kubernetes.db.enabled"
|
||||
value="false"
|
||||
/>
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
17
.idea/.idea.biergarten/.idea/data_source_mapping.xml
generated
17
.idea/.idea.biergarten/.idea/data_source_mapping.xml
generated
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourcePerFileMappings">
|
||||
<file
|
||||
url="file://$APPLICATION_CONFIG_DIR$/consoles/db/7eb1584d-925b-46f8-a3a2-a73152a2d625/console.sql"
|
||||
value="7eb1584d-925b-46f8-a3a2-a73152a2d625"
|
||||
/>
|
||||
<file
|
||||
url="file://$PROJECT_DIR$/DataLayer/scripts/01-schema/schema.sql"
|
||||
value="7eb1584d-925b-46f8-a3a2-a73152a2d625"
|
||||
/>
|
||||
<file
|
||||
url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/02-UserCredential/USP_AddUserCredential.sql"
|
||||
value="7eb1584d-925b-46f8-a3a2-a73152a2d625"
|
||||
/>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/.idea.biergarten/.idea/indexLayout.xml
generated
8
.idea/.idea.biergarten/.idea/indexLayout.xml
generated
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
15
.idea/.idea.biergarten/.idea/sqldialects.xml
generated
15
.idea/.idea.biergarten/.idea/sqldialects.xml
generated
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/01-schema/schema.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/02-functions/UDF_GetCountryIdByCode.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/02-functions/UDF_GetStateProvinceIdByCode.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/01-UserAccount/USP_CreateUserAccount.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/01-UserAccount/USP_GetAllUserAccounts.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/01-UserAccount/USP_GetUserAccountByEmail.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/01-UserAccount/USP_GetUserAccountById.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/01-UserAccount/USP_GetUserAccountByUsername.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/02-UserCredential/USP_AddUserCredential.sql" dialect="TSQL" />
|
||||
<file url="file://$PROJECT_DIR$/DataLayer/scripts/03-crud/03-UserVerification/USP_AddUserVerification.sql" dialect="TSQL" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.biergarten/.idea/vcs.xml
generated
6
.idea/.idea.biergarten/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
6
DBSeed/ISeeder.cs
Normal file
6
DBSeed/ISeeder.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
interface ISeeder
|
||||
{
|
||||
Task SeedAsync(SqlConnection connection);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace DBSeed;
|
||||
|
||||
internal static class LocationSeeder
|
||||
class LocationSeeder : ISeeder
|
||||
{
|
||||
private static readonly IReadOnlyList<(
|
||||
string CountryName,
|
||||
@@ -244,7 +244,7 @@ internal static class LocationSeeder
|
||||
("MX-ZAC", "Zacatecas"),
|
||||
];
|
||||
|
||||
internal static async Task SeedAsync(SqlConnection connection)
|
||||
public async Task SeedAsync(SqlConnection connection)
|
||||
{
|
||||
foreach (var (countryName, countryCode) in Countries)
|
||||
{
|
||||
|
||||
@@ -16,11 +16,18 @@ try
|
||||
|
||||
Console.WriteLine("Connected to database.");
|
||||
|
||||
await LocationSeeder.SeedAsync(connection);
|
||||
Console.WriteLine("Seeded locations.");
|
||||
ISeeder[] seeders =
|
||||
[
|
||||
new LocationSeeder(),
|
||||
new UserSeeder(),
|
||||
];
|
||||
|
||||
await UserSeeder.SeedAsync(connection);
|
||||
Console.WriteLine("Seeded users.");
|
||||
foreach (var seeder in seeders)
|
||||
{
|
||||
Console.WriteLine($"Seeding {seeder.GetType().Name}...");
|
||||
await seeder.SeedAsync(connection);
|
||||
Console.WriteLine($"{seeder.GetType().Name} seeded.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Seed completed successfully.");
|
||||
return 0;
|
||||
|
||||
@@ -7,10 +7,12 @@ using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace DBSeed;
|
||||
|
||||
internal static class UserSeeder
|
||||
class UserSeeder : ISeeder
|
||||
{
|
||||
private static readonly IReadOnlyList<(string FirstName, string LastName)>
|
||||
SeedNames =
|
||||
private static readonly IReadOnlyList<(
|
||||
string FirstName,
|
||||
string LastName
|
||||
)> SeedNames =
|
||||
[
|
||||
("Aarya", "Mathews"),
|
||||
("Aiden", "Wells"),
|
||||
@@ -114,7 +116,7 @@ internal static class UserSeeder
|
||||
("Zoie", "Armstrong"),
|
||||
];
|
||||
|
||||
public static async Task SeedAsync(SqlConnection connection)
|
||||
public async Task SeedAsync(SqlConnection connection)
|
||||
{
|
||||
var generator = new PasswordGenerator();
|
||||
var random = new Random();
|
||||
|
||||
21
README.md
21
README.md
@@ -5,10 +5,10 @@ This solution is a monolith-oriented Web API with a layered structure. The curre
|
||||
## High-level projects
|
||||
|
||||
- `WebAPI/` - ASP.NET Core API endpoints (controllers) and application entrypoint.
|
||||
- `BusinessLayer/` - Intended home for domain/business logic (currently minimal).
|
||||
- `BusinessLayer/` - Intended home for domain/business logic
|
||||
- `DataAccessLayer/` - Repository implementations, entities (POCOs), and SQL helpers.
|
||||
- `DataLayer/` - Database schema, seed scripts, and data sources.
|
||||
- `WebCrawler/` - Separate crawler executable.
|
||||
- `DataLayer/` - DbUp console app that applies embedded schema/functions/procedures.
|
||||
- `DBSeed/` - Console app for seeding locations and test user data.
|
||||
- `DALTests/` - Data access tests.
|
||||
|
||||
## Data access architecture
|
||||
@@ -16,12 +16,12 @@ This solution is a monolith-oriented Web API with a layered structure. The curre
|
||||
- **Entities (POCOs)** live in `DataAccessLayer/Entities/`.
|
||||
- **Repositories** live in `DataAccessLayer/Repositories/` and implement interfaces like `IUserAccountRepository`.
|
||||
- **SQL execution** lives in `DataAccessLayer/Sql/`.
|
||||
- **Stored procedures** for CRUD live under `DataAccessLayer/Sql/crud/` and are invoked by repositories.
|
||||
- **Stored procedures** for CRUD live under `DataLayer/scripts/03-crud/` and are invoked by repositories.
|
||||
|
||||
Example flow:
|
||||
|
||||
```
|
||||
WebAPI Controller -> IUserAccountRepository -> UserAccountRepository -> stored procedure
|
||||
WebAPI Controller -> UserService -> UserAccountRepository -> stored procedure
|
||||
```
|
||||
|
||||
The repositories are currently responsible for:
|
||||
@@ -29,12 +29,13 @@ The repositories are currently responsible for:
|
||||
- Executing stored procedures
|
||||
- Mapping result sets to POCOs
|
||||
|
||||
## Database schema and seed
|
||||
## Database schema and seed tooling
|
||||
|
||||
- `DataLayer/schema.sql` contains the database schema definitions.
|
||||
- `DataLayer/database/` holds application functions and CRUD procedures.
|
||||
- `DataLayer/seed/` holds seed-only procedures and the `SeedDB.cs` entry point.
|
||||
- `SeedDB.cs` honors `SEED_MODE` (`database`, `seed`, or `all`) to control which scripts run.
|
||||
- `DataLayer/scripts/01-schema/schema.sql` contains the database schema definitions.
|
||||
- `DataLayer/scripts/02-functions/` holds application functions.
|
||||
- `DataLayer/scripts/03-crud/` holds CRUD stored procedures.
|
||||
- `DataLayer/Program.cs` runs DbUp to apply embedded scripts to the database.
|
||||
- `DBSeed/Program.cs` runs the location and user seeders using `DB_CONNECTION_STRING`.
|
||||
|
||||
## Key conventions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user