Skip to content

Feature/postgre#375

Merged
Pierre-Demessence merged 27 commits into
masterfrom
feature/postgre
Apr 6, 2026
Merged

Feature/postgre#375
Pierre-Demessence merged 27 commits into
masterfrom
feature/postgre

Conversation

@Pierre-Demessence

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 1, 2026 02:59
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

🚀 Deploy this PR

To deploy this branch to the dev environment, go to the Deploy PR to Dev workflow and click Run workflow with this PR number.

This will build a Docker image from your branch, push it to GHCR, and trigger an ArgoCD sync.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the bot’s database layer and deployment configuration from MySQL to PostgreSQL (including updated connection strings, K8s manifests, and Docker Compose), and replaces the MySQL EVENT-based karma reset mechanism with an in-app scheduled service.

Changes:

  • Switched DB connectivity from MySql.Data/MySqlConnection to Npgsql + Insight.Database PostgreSQL provider and updated SQL for PostgreSQL.
  • Added KarmaResetService to handle weekly/monthly/yearly karma resets (replacing MySQL EVENT scheduler).
  • Updated dev/prod Kubernetes manifests, secrets, and docs to use PostgreSQL + pgAdmin and added PostgreSQL backup manifests.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
README.md Updates documentation for PostgreSQL setup and formatting adjustments.
k8s/prod/postgresql.yaml Replaces MySQL Deployment/Service/PVC with PostgreSQL equivalents in prod.
k8s/prod/postgresql-backup.yaml Adds a PostgreSQL backup Deployment for prod.
k8s/prod/pgadmin.yaml Replaces phpMyAdmin with pgAdmin in prod.
k8s/prod/mysql-backup.yaml Removes the MySQL backup Deployment from prod.
k8s/prod/external-secrets.yaml Renames MySQL secrets to PostgreSQL + adds pgAdmin credentials secret in prod.
k8s/prod/bot.yaml Updates bot DB secret ref and init container to wait for PostgreSQL in prod.
k8s/prod/bot-config.yaml Updates prod Settings.json connection string to PostgreSQL.
k8s/dev/postgresql.yaml Replaces MySQL Deployment/Service/PVC with PostgreSQL equivalents in dev.
k8s/dev/postgresql-backup.yaml Adds a PostgreSQL backup Deployment for dev.
k8s/dev/pgadmin.yaml Replaces phpMyAdmin with pgAdmin in dev.
k8s/dev/mysql-backup.yaml Removes the MySQL backup Deployment from dev.
k8s/dev/external-secrets.yaml Renames MySQL secrets to PostgreSQL + adds pgAdmin credentials secret in dev.
k8s/dev/bot.yaml Updates bot DB secret ref and init container to wait for PostgreSQL in dev.
k8s/dev/bot-config.yaml Updates dev Settings.json connection string to PostgreSQL.
docs/plans/done/mysql-to-postgresql-migration.md Adds a “done” migration plan/summary document.
docker-compose.yml Switches local dev stack from MySQL + phpMyAdmin to PostgreSQL + pgAdmin.
DiscordBot/Settings/Settings.example.json Updates example DB connection string for PostgreSQL.
DiscordBot/Services/KarmaResetService.cs Adds polling-based karma reset scheduler + meta table tracking.
DiscordBot/Services/DatabaseService.cs Switches DB connections to Npgsql and rewrites schema creation for PostgreSQL.
DiscordBot/Program.cs Registers and eagerly resolves KarmaResetService.
DiscordBot/Modules/ModerationModule.cs Removes unused BouncyCastle import and minor formatting.
DiscordBot/Extensions/UserDBRepository.cs Updates INSERT patterns and rank ordering for PostgreSQL.
DiscordBot/Extensions/DBConnectionExtension.cs Replaces SHOW COLUMNS with information_schema query.
DiscordBot/Extensions/CasinoRepository.cs Updates INSERT patterns and JSON handling for PostgreSQL.
DiscordBot/DiscordBot.csproj Removes MySql.Data and adds Insight.Database PostgreSQL provider package.
Comments suppressed due to low confidence (1)

DiscordBot/Extensions/CasinoRepository.cs:16

  • Same identifier-casing issue as ServerUserRepo: these queries use unquoted identifiers from CasinoProps, but DatabaseService creates the casino tables with quoted mixed-case column names. In PostgreSQL, unquoted identifiers are folded to lowercase and won't match quoted mixed-case columns; align schema + query quoting/casing consistently.
    [Sql($@"
    INSERT INTO {CasinoProps.CasinoTableName} ({CasinoProps.UserID}, {CasinoProps.Tokens}, {CasinoProps.CreatedAt}, {CasinoProps.UpdatedAt}, {CasinoProps.LastDailyReward}) 
    VALUES (@{CasinoProps.UserID}, @{CasinoProps.Tokens}, @{CasinoProps.CreatedAt}, @{CasinoProps.UpdatedAt}, @{CasinoProps.LastDailyReward})
    RETURNING *")]
    Task<CasinoUser> InsertCasinoUser(CasinoUser user);

    [Sql($"SELECT * FROM {CasinoProps.CasinoTableName} WHERE {CasinoProps.UserID} = @userId")]
    Task<CasinoUser> GetCasinoUser(string userId);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DiscordBot/Services/DatabaseService.cs Outdated
Comment thread DiscordBot/Extensions/UserDBRepository.cs
Comment thread DiscordBot/Services/KarmaResetService.cs
Comment thread k8s/prod/postgresql-backup.yaml Outdated
Comment thread k8s/dev/postgresql-backup.yaml Outdated
Comment thread README.md
Comment thread README.md Outdated
Comment thread DiscordBot/DiscordBot.csproj Outdated
@Pierre-Demessence

Copy link
Copy Markdown
Member Author

/build

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

🐳 Build complete!

Image: ghcr.io/unity-developer-community/udc-bot-dev:832a135

To deploy with manifest changes:

  1. Update k8s/dev/bot.yaml image tag to 832a135 on your branch
  2. Switch ArgoCD dev target revision to your branch

@Pierre-Demessence

Copy link
Copy Markdown
Member Author

/build

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

🐳 Build complete!

Image: ghcr.io/unity-developer-community/udc-bot-dev:17fc156

To deploy with manifest changes:

  1. Update k8s/dev/bot.yaml image tag to 17fc156 on your branch
  2. Switch ArgoCD dev target revision to your branch

Pierre-Demessence and others added 7 commits April 3, 2026 22:05
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…ntials

Co-authored-by: Copilot <copilot@github.com>
…eserve data during migration

- Rename TransactionType enum to TransactionKind (avoids DB column name collision)

- Replace Type (integer) column with TransactionType (varchar) to match MySQL

- Replace DetailsJson (jsonb) column with Description (text) to match MySQL

- Add TargetUserID column for migration compatibility

- Update CasinoProps constants, repository SQL, and all consumer references
- Create mysql-to-postgresql-changes.md with full schema, code, and infra details

- Update data-migration-mysql-to-postgresql.md with working pgloader config

- Delete outdated mysql-to-postgresql-migration.md summary

- Update docs/INDEX.md with new doc links
- Add token_transactions to table matching regex (dev + prod)

- Add BEFORE LOAD: DROP+CREATE token_transactions with MySQL-compatible schema

- Ensures existing PG tables with old column names are replaced before import
@Pierre-Demessence

Copy link
Copy Markdown
Member Author

/build

@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown

🐳 Build complete!

Image: ghcr.io/unity-developer-community/udc-bot-dev:d6223c0

To deploy with manifest changes:

  1. Update k8s/dev/bot.yaml image tag to d6223c0 on your branch
  2. Switch ArgoCD dev target revision to your branch

Pierre-Demessence and others added 3 commits April 4, 2026 03:37
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@Pierre-Demessence Pierre-Demessence merged commit c7d4b97 into master Apr 6, 2026
5 checks passed
@Pierre-Demessence Pierre-Demessence deleted the feature/postgre branch April 6, 2026 16:08
@Pierre-Demessence Pierre-Demessence restored the feature/postgre branch April 6, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants