Skip to content

Conversation

@lenstr
Copy link

@lenstr lenstr commented Oct 23, 2025

Summary

  • Add --skip-db-creation flag to enable running migrations on pre-existing databases without CREATE DATABASE permissions
  • Enables scenarios where database creation is managed centrally while migration execution is delegated to users with limited privileges

Problem

When granting database users (e.g., analysts) permission to run migrations on their dedicated databases, they may not have CREATE DATABASE privileges for security reasons. The current implementation always attempts to run CREATE DATABASE IF NOT EXISTS, which fails even when the database already exists and was pre-created by administrators.

Solution

Added a new --skip-db-creation flag (and corresponding CH_MIGRATIONS_SKIP_DB_CREATION environment variable) that skips the database creation step, allowing users to run migrations on existing databases without requiring CREATE DATABASE permissions.

Use Case

This enables scenarios where:

  • Databases are managed centrally by DBAs/administrators
  • Migration execution is delegated to analysts or developers
  • Users need minimal permissions (just table/schema management, not database creation)

Changes

  • Added --skip-db-creation CLI option and CH_MIGRATIONS_SKIP_DB_CREATION environment variable
  • Modified migration() function to conditionally skip create_db() when flag is set
  • Updated README with documentation and usage example
  • Added integration test to verify skip functionality
  • All existing tests pass (31/31)

Example Usage

```bash
clickhouse-migrations migrate
--host=http://localhost:8123
--user=analyst
--password='***'
--db=analytics
--migrations-home=/path/to/migrations
--skip-db-creation
```

@lenstr lenstr force-pushed the feature/skip-database-creation branch from d0bd3a0 to fdc5a76 Compare October 23, 2025 16:02
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