lucid
lucid copied to clipboard
Add db:create command
Why this feature is required (specific use-cases will be appreciated)?
We have found ourselves having to manually create the databases in both development and testing environment relying on external tools such as Docker or custom scripts to achieve this. Being inspired in Laravel and Rails, it might be awesome to add a command that attempts to create the database for the given environment.
Bonus: In Rails, in development mode, it creates the database for both the development and testing environment.
Have you tried any other work arounds?
Yes, we have a dockerfiile with an entrypoint that creates the database for both environments.
Are you willing to work on it with little guidance?
Yes, I tried to do a proof of concept by taking inspiration from https://github.com/adonisjs/lucid/blob/develop/commands/DbWipe.ts but the problem is that in these scenarios the database is already setup, so doing something like:
public async run() {
const db = this.application.container.use('Adonis/Lucid/Database')
//this.connection = this.connection || db.primaryConnectionName
//const connection = db.connection(this.connection || db.primaryConnectionName)
const connection = db.connection(db.primaryConnectionName)
const result = await connection.knexRawQuery('CREATE DATABASE some_db')
}
Wont work since the db.connection will attempt to connect to the configured database (I am using Postgres)
Hello @matiasgarcia 👋
Yup, it is a nice to have feature. I am not sure if I can pick it up right away, but happy to merge the PR if you or someone else can research and see how to best implement this.
Maybe, we can see if someone in the Knex community has created something similar and take inspiration from that.
Maybe we can get some inspiration from this, will check it out https://github.com/Vincit/knex-db-manager/blob/master/lib/PostgresDatabaseManager.js
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.