shoito / prismarls

MIT License
2 stars 1 forks source link

feat: Support Multiple Migration Directories #1

Open wasuwas opened 2 days ago

wasuwas commented 2 days ago

Support Multiple Migration Directories

Overview

Currently, the tool only appends RLS (Row-Level Security) settings to the latest migration file. However, in practical, migration directories are often created each time the schema.prisma file is modified. This results in CREATE TABLE SQL statements being scattered across multiple migration directories.

I propose to enhance the tool to support multiple migration directories, allowing it to apply RLS settings across all relevant migrations, not just the latest one. This enhancement will make the tool more versatile and better aligned with typical Prisma migration patterns, where schema changes may be spread across multiple migrations over time.

Proposed changes

  1. Modify the tool to scan all migration directories within the specified migrations path.
  2. For each migration directory found, analyze the SQL files to identify CREATE TABLE statements.
  3. Append appropriate RLS settings to each identified table creation, regardless of which migration directory it's in.
shoito commented 1 day ago

@wasuwas Thank you for your suggestion.

However, I cannot accept the proposal to modify a deployed migration file. Once prisma migrate deploy has been executed, altering an applied migration file will result in a checksum mismatch with the records in the _prisma_migrations table.

Therefore, I generate migration files without applying them by using the --create-only option with the prisma migrate dev --create-only command. This approach ensures that only the latest migration files are targeted.

If the proposed change in item 3 could be implemented in a new migration file instead of modifying a deployed one, that would be ideal. I recognize that there are still many areas for improvement in prismarls, and I appreciate your continued suggestions.