This repository contains the code for the Judge and Tournament Registration websites for NoVA North Odyssey of the Mind.
Project Name | .NET Version | Purpose |
---|---|---|
docker-compose | N/A | Docker Compose file |
Odyssey.Database | SQL Server 2019 | Database management |
OdysseyCoreMvc | .NET 6.0 | Unused (I think): Core MVC framework |
OdysseyMvc2023 | .NET Framework 4.8 | MVC framework 2023 |
OdysseyMvc4 | .NET Framework 4.8 | MVC framework 4 |
OdysseyMvc4.Tests | .NET Framework 4.8 | MVC framework 4 tests |
OdysseyRegistrationWebApi | .NET 8.0 | Web API for registration |
UpdateProblemSynopsesForRegistration | .NET Framework 4.8 | Update problem synopses |
The OdysseyMvc4 (original) and OdysseyMvc2023 (current) projects are currently built using ASP.NET MVC version 4 on .NET Framework 4.8.
Tip
TODO: Update the projects to use ASP.NET (Core) 8.0 or later.
Make sure to copy the web.config file from this directory, i.e., the top-most directory, into the root directory of your website.
Note
This should be placed in a higher directory than your bin, Content, Views, etc. directories. The directory containing those subdirectories will likely have its own web.config file.
- Make sure that the ASP.NET MVC website directory is set as an application starting point.
- Log into the Winhost Control Panel.
- Navigate to the Odyssey website.
- Navigate to the Sites List -> Site Manager -> Application Starting Point page.
- Make sure that the path to the directory containing the website is registered as an application starting point, e.g. /registration.
- Make sure to back up the database after every season (or before the next one).
Tip
TODO: Document how I added the SQL Project to Visual Studio and how to modify, use, and deploy it.
Site: novanorth.org
As of 09/29/2024, this is the configuration of the registration database.
Database Name: DB_12824_registration
Version: MS SQL 2008 R2
Database Server: s06.winhost.com
Database User: DB_12824_registration_user
Assigned Quota: 25 MB
Usage: 4 MB
Connection String: "Data Source=tcp:s06.winhost.com;Initial Catalog=DB_12824_registration;User ID=DB_12824_registration_user;Password=******;Integrated Security=False;"
Open a PowerShell prompt.
docker pull mcr.microsoft.com/mssql/server:2022-latest
docker volume create sql-volume
$mssql_sa_password = "" # set this to a strong password
docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$mssql_sa_password" -p 1433:1433 --name sql1 --hostname sql1 --mount "source=sql-volume,target=/sqldata" -d mcr.microsoft.com/mssql/server:2022-latest
docker exec -it -u 0 sql1 "bash" # -u 0 lets us log in as root.
chmod 777 /sqldata
docker container exec sql1 /opt/mssql-tools/bin/sqlcmd -U sa -P "$mssql_sa_password" -Q "CREATE DATABASE [DB_12824_registration] ON PRIMARY ( NAME = N'DB_12824_registration_data', FILENAME = N'/sqldata/DB_12824_registration_data.mdf' , SIZE = 4160KB , MAXSIZE = 25600KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'DB_12824_registration_log', FILENAME = N'/sqldata/DB_12824_registration_log.ldf' , SIZE = 1024KB , MAXSIZE = 1024000KB , FILEGROWTH = 65536KB );"`
docker cp "2022-08-06 - NoVA North Production Database Export Script.sql" sql1:/sqldata
docker container exec sql1 /opt/mssql-tools/bin/sqlcmd -U sa -P "$mssql_sa_password" -i "/sqldata/2022-08-06 - NoVA North Production Database Export Script.sql"
This will create a Mermaid database schema diagram from your SQL Server database.
-
Download latest version: Release v0.4.1 � KarnerTh/mermerd � GitHub
-
Unzip it.
-
Make sure your SQL Server database is up, e.g., in Docker.
-
Run the following command:
Downloads\mermerd_0.4.1_windows_amd64.tar\mermerd -c "sqlserver://sa:********@localhost:1433?database=DB_12824_registration" -s dbo --useAllTables -o OdysseySchema.mmd
-
You will find your file created as OdysseySchema.mmd in the directory where you ran the tool.
Tip
TODO: Read "Get started with Entity Framework Core and an existing database in minutes - Quick Start Guide": https://x.com/ErikEJ/status/1740635086742069720. This can produce Mermaid diagrams, as well.
docker stop sql1 ; docker rm sql1`
- Navigate to Application Starting Point.
- Click "Create".
- Enter "/test" as the subdirectory.
- Click "Create".
- You should see a message that the site was created successfully.
- TODO: Add instructions.
- TODO: Add instructions.
- TODO: Add instructions.
- Rolled back to EF 4.4 to make sure everything worked. See if the code works as-is with EF 6.x.
- Create Elmah test DB
- Determine what all the projects in this solution are for.
- Upgrade the Odyssey.Database project to SQL Server 2022.
- Clean up the "Purpose" column in the Projects table above.
- Add logging to all projects!
- Make all "Return to the Home Page" buttons return to the home page at the current base URL, not hard-coded to a specific Odyssey Registration home page.
Created a new project in the solution named OdysseyRegistrationWebApi
- Right-clicked on the sln and selected "Add, New Project..."
- Selected "ASP.NET Core Web API".
- Used the following options:
- .NET 8.0 (Long Term Support)
- Authentication type: None (I may need to fix this later)
- Configure for HTTPS: checked
- Enable container support: checked
- Do not use top-level statements: unchecked
- Use controllers: checked
- Enlist in .NET Aspire orchestration: unchecked
- I was then prompted with:
⚠️ This solution contains packages with vulnerabilities. Manage NuGet Packages.- Clicked the "Manage NuGet Packages" link.
- I checked "Show only vulnerable".
- jQuery.UI.Combined needed to be updated from 1.10.3 to 1.13.2.
- The only project using it looks like OdysseyMvc4.
- I still got vulnerability warnings in my build output.
- Upgraded jQuery 2.0.3 in OdysseyMvc4.
- jQuery.UI.Combined 1.10.3 OdysseyMvc4.
-
In VS 2022, I right-clicked on the solution and selected Add, Container Orchestrator Support.
- Docker Compose
- Linux Containers
-
I updated the docker-compose.yml file with the contents of one I found for adding a SQL Server 2022 database, modifying it by leveraging Docker Compose secrets.
db: image: mcr.microsoft.com/mssql/server:2022-latest environment: MSSQL_SA_PASSWORD_FILE: /run/secrets/sa_password ACCEPT_EULA: "Y" ports: - "1433:1433"
-
I followed the instructions here: https://stackoverflow.com/questions/69941444/how-to-have-docker-compose-init-a-sql-server-database.
-
I created init\init.sql with the following content.
USE [master]; GO IF NOT EXISTS (SELECT * FROM sys.sql_logins WHERE name = 'vaodyssey') BEGIN CREATE LOGIN [vaodyssey] WITH PASSWORD = '********', CHECK_POLICY = OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER [vaodyssey]; END GO
-
I copied "OdysseyRegistration\Odyssey.Database\Scripts\2023-12-02 - NoVA North Registration Prod Backup.sql" to OdysseyRegistration\init\novanorth-prod.sql.
-
I added a new command to the dockercompose.yml file to create and initialize the Odyssey Registration database:
/opt/mssql-tools/bin/sqlcmd -S sqlserver -U sa -P ${Sa_Password:-********} -d master -i docker-entrypoint-initdb.d/novanorth-prod.sql;
-
Replaced passwords in docker-compose.yml file: https://docs.docker.com/compose/use-secrets/
- I'm figuring out where I left off and what everything does in the .sln.
- I believe the OdysseyMvc2023 project is the main project that runs on my desktop against a SQL Server database running in a local Docker container.
- When I built the docker-compose project in the .sln, it built two projects:
- OdysseyRegistrationWebApi
- docker-compose
- Then I right-click on the docker-compose project and select "Compose Up".
- The sqlserver.configurator-1 container starts and exits.
- The sqlserver-1 container starts and keeps running.
- The odysseyregistrationwebapi-1 container starts and keeps running.
- I can now run SQL Server Management Studio (SSMS) and connect to the SQL Server database running in the sqlserver-1 container.
- The database is fully populated with the data from the novanorth-prod.sql script.
- I think that's where the data came from. I need to verify this.
- The database is fully populated with the data from the novanorth-prod.sql script.
- The login for the user in the Odyssey Registration MVC app failed, but otherwise I think it's working on my desktop.
- I updated OdysseyRegistration\OdysseyMvc2023\Web.config with Data Source=localhost (i.e., Docker), user=sa, and password=********.
- The following code threw an exception in OdysseyRegistration\OdysseyMvc2023\Models\OdysseyRepository.cs on line 355.
Event tournamentInfo = this.tournamentInfo ?? (this.TournamentInfo = Queryable.Where<Event>((IQueryable<Event>)this.context.Events, (Expression<Func<Event, bool>>)(o => o.EventName.StartsWith(this.RegionName) && o.EventName.Contains("Tournament"))).First<Event>());
- The
EventName
in theEvents
DB table needed to be renamed from "NoVA North Regional Tournament" to "NoVA North and NoVA South Regional Tournament". - This is because I'm using last year's DB data and we were a combined region last year.
- The code continued after this name change!!!
- The web site is running locally!
- Judges and Tournament Registration show as "(Coming Soon!)"
- I commented these lines out and uncommented the lines that allow you to proceed to the registration pages.
- Now both the Judges and Tournament Registration pages are showing Closed.
Run MySQL in a Docker container locally:
docker run --name mysql -e MYSQL_ROOT_PASSWORD=<any password to connect> -v C:\Users\Rob\Downloads:/downloads -d mysql:latest
Open a shell in the Docker container:
docker exec -it mysql bash
Create a dump file of the MySQL database:
mysqldump -u vaodyss -p mysql_12824_wordpress -h my01.winhost.com > dump.sql
or
Connect to the MySQL server:
mysql -u vaodyss -p mysql_12824_wordpress -h my01.winhost.com
Copy the dump file out of the Docker container:
docker cp mysql:/dump.sql C:\Users\rob\Downloads\
Restore/Import the MySQL database on the new server:
mysql -u vaodyssey -p mysql_12824_wordpress24 -h my06.winhost.com < dump.sql
I modified our /wp/wp-config.php file to point to the new MySQL 8.x database.
-
Used EF Core Power Tools to reverse engineer the Odyssey Registration database.
-
To export data from the current SQL database as JSON, run a query like the following in SSMS:
SELECT * FROM Schools FOR JSON AUTO
-
Add a link like
entity.HasData(SeedHelper.SeedData<School>("Schools.json"));
to themodelBuilder.Entity<School>()
code within theOnModelCreating
method in theOdysseyContext
class. -
Added EF migrations using the Developer PowerShell for VS 2022 window.
-
Used the following commands:
- dotnet ef migrations add InitialCreate
- dotnet ef database update
- dotnet ef migrations add UpdateConfigSeedData
- dotnet ef database update
- dotnet ef migrations add UpdateSchoolsSeedData
- dotnet ef database update