Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom casing in schema push operations #3831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stefan-gorules
Copy link

Problem

When using drizzle with custom casing options (e.g., casing: 'snake_case'), the pushSchema operation doesn't respect the configured casing. This leads to mismatches between the runtime configuration and schema synchronization.

Example of the issue:

// Database configuration using snake_case
export const db = drizzle({ 
  client: pgPool, 
  casing: 'snake_case', 
  schema: dbSchema 
});

// Auto-sync function that previously didn't respect casing
export const autoSynchronize = async () => {
  // This would generate schema with default casing, causing mismatch
  const result = await pushSchema(dbSchema, db as any);
  if (result.hasDataLoss) {
    log.fatal('executing database synchronisation would lead to data loss, aborting');
    return;
  }

  await result.apply();
};

Solution

Added a new optional casing parameter to pushSchema that gets passed through to generateDrizzleJson. This ensures the schema generation respects the same casing rules that are used in the database connection configuration.

Updated Usage

// Schema push with matching casing
const result = await pushSchema(
  dbSchema, 
  db as any, 
  undefined, 
  undefined, 
  undefined, 
  'snake_case'
);

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.

1 participant