You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue proposes the addition of a new built-in management command, marten createdb, that creates the PostgreSQL (or MySQL) database defined in the project settings — before running marten migrate.
Background
Currently, Marten assumes the target database already exists before running marten migrate. This means developers must create the database manually (e.g. createdb myapp_dev or via psql) before they can run migrations for the first time.
This is a friction point in the onboarding flow:
# Current flow (manual step required)
createdb myapp_development # ← must be done manually
marten migrate
marten serve
Rails solves this with rails db:create. Django assumes the database exists (no equivalent command). Marten would benefit from a similar convenience command.
Proposed Solution
Introduce a marten createdb management command that:
Reads the database configuration from Marten.settings.databases (the "default" connection)
Connects to the database server's system database (postgres for PostgreSQL, mysql for MySQL) to issue a CREATE DATABASE statement
Is idempotent: if the database already exists, it prints a notice and exits cleanly (no error)
Handles errors gracefully with a descriptive message
Example output
$ marten createdb
Creating database myapp_development ...
✓ Database myapp_development created successfully.
$ marten createdb # run again
Creating database myapp_development ...
✓ Database myapp_development already exists.
This discussion was converted from issue #350 on April 06, 2026 14:23.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Description
This issue proposes the addition of a new built-in management command,
marten createdb, that creates the PostgreSQL (or MySQL) database defined in the project settings — before runningmarten migrate.Background
Currently, Marten assumes the target database already exists before running
marten migrate. This means developers must create the database manually (e.g.createdb myapp_devor viapsql) before they can run migrations for the first time.This is a friction point in the onboarding flow:
Rails solves this with
rails db:create. Django assumes the database exists (no equivalent command). Marten would benefit from a similar convenience command.Proposed Solution
Introduce a
marten createdbmanagement command that:Marten.settings.databases(the"default"connection)postgresfor PostgreSQL,mysqlfor MySQL) to issue aCREATE DATABASEstatementExample output
Desired onboarding flow
Implementation Notes
src/marten/cli/manage/command/create_db.crpostgressystem database and runCREATE DATABASE "<name>"CREATE DATABASE IF NOT EXISTS \``host,port,user, andpasswordfrom settingsRelationship to Existing Issues
This complements #148 (
marten cleardatabase):createdbcreates the database,cleardatabaseresets its content, andmigratepopulates its schema.References
rails db:create— https://guides.rubyonrails.org/command_line.htmlmarten cleardatabasemanagement command #148: Add amarten cleardatabasemanagement commandmarten seedmanagement command #147: Add amarten seedmanagement commandBeta Was this translation helpful? Give feedback.
All reactions