Chore: refactor templates and centralize validations - #35
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1 - Database-Native Type Centralization:
- Define schema/native_types.go, mapping Prisma native types to SQL data types, Go runtime types, and required database extensions
- Replace long hardcoded switch blocks in nativeTypeToSQL() and unsupportedToGoType() with lookups into the new central types map
- Dynamically resolve types in injectRequiredExtensions() using the same central map
2 - Client & Embedded Runtime Refactoring:
- Create a unified runtime template (runtime.gotpl) containing dialects, DBTX, custom errors, and flat validations
- Consolidate and strip all external runtime dependencies to keep the generated client completely self-contained
- Wrap net and hstore package imports and validation methods in conditional blocks (hasNetAnywhere and hasHstoreAnywhere), emitting them only when required by the schema
- Optimize code generator templates (model_create.gotpl) to use generalized loops (ToRowMap) and flat validations instead of duplicating field loops.
3 - Testing & Automation Improvements:
- Implement a bidirectional schema switcher in prepareSchema.js to back up and restore PG-specific syntax when switching dialects.
- Add SQLite (test-sqlite), PostgreSQL (test-pg), and double-engine (test-dbs) test targets to the makefile.
- Write a multi-step schema evolution test suite (evolution_test.go) that simulates database migrations (optional fields, defaults, unique checks, relationships) inside a sandbox