platformplatform / PlatformPlatform

Alpha state. A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
https://platformplatform.github.io
MIT License
253 stars 26 forks source link

Switch ID columns to varchar(32) to prevent padding issues #622

Closed tjementum closed 6 days ago

tjementum commented 6 days ago

Summary & Motivation

Switch ID columns from char(xx) to varchar(32) to eliminate issues with blank spaces when saving strongly typed IDs like usr_01JA5QZTCP69B5T916WF1TSQG8 (30 characters). Developers often forget to adjust column sizes when copying migration code, causing unnecessary padding in char columns. Defaulting to varchar(32) provides flexibility for IDs up to 32 characters without blank space issues and supports strongly typed IDs with up to 5-character prefixes. The signup ID column remains varchar(33) due to the lack of a suitable 5-character prefix for "signup."

Downstream Projects

Update all Entity Framework database migrations to replace char(xx) with varchar(32) for ID columns. Note that this is a non-breaking change, as the original EF Core migration is updated instead of creating a new one, ensuring the existing schema remains compatible.

Checklist

linear[bot] commented 6 days ago

PP-237 Switch ID columns from char(xx) to varchar(32)

sonarcloud[bot] commented 6 days ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

raix commented 6 days ago

@tjementum maybe there could be a helper method on the strongly typed id to provide the table.Column<string>("varchar(33)", nullable: false), based on the prefix?

tjementum commented 6 days ago

This is a temporary fix.

I deliberately keep EF Migrations like this, so one could still use the EF Migrations tools to generate the migrations.

I have a working prototype of database migrations using a declarative way of maintaining the database schema.