How can ddev automatically create additional databases? - ddev

This is a followup question to How can I create and load a second database in ddev?. It is about doing that task automatically.
One use case for this is developing a migration to Drupal from another MySQL database, and collaborating with others on the migration. If the database name can be set by ddev, additional developers can get the database created automatically, and additional databases can be added to their settings.local.php, using known values.

Try this in your project's config.yaml:
hooks:
post-start:
- exec: mysql -uroot -proot -hdb -e "CREATE DATABASE IF NOT EXISTS another_db; GRANT ALL ON another_db.* TO 'db'#'%';"

Related

Gobuffalo error "There is no connection named development defined!"

In my go project I install gobuffalo:
go get github.com/gobuffalo/pop/...
And then I run soda migrate but I got this error There is no connection named development defined!
Does anyone know what problem I am facing with?
First a quick reply, explanation below.
Delete the database.yml file.
Force soda to create the same file with the command "soda g config"
After that my "soda migrate" command stopped giving the error and worked. (Don't forget to put your db cofig details in the generated file in the first section (development) only)
In Detail
Actually I copied an old working directory of Go to create another one. In the new place it was not working. I think that was the problem. If still not working try installing SODA and do the above in the new place, I did that also.
https://gobuffalo.io/documentation/database/soda/
https://gobuffalo.io/documentation/database/configuration/
For me, I named the file database.yaml initially, changing the name of file to database.yml worked just fine.
Please ensure you don't have any formatting extension's available I was initially getting the same issue later resolved by 'uninstalling' prettier.
Steps I followed:
'soda g config' and edit your database.yml (make sure it is 'database.yml')
I was also creating some Fizz migrations 'soda generate fizz table_name'
Edit changes to the database.yml file (I am using Dbeaver by default it usually asks you to set user as 'postgres' and if you have any password set in order to make connection with 'postgres' you can use that same password in the password)
i.e
development:
dialect: postgres
database: db_name
user: postgres
password: ****
host: 127.0.0.1
pool: 5
now you can use 'soda migrate' or 'soda migrate up' in case you have some
code there for creating a table
may this approach helps :)

Laravel sail multiple databases

I'm using laravel sail and trying to create another database for my Laravel project which required to use multiple databases connections, I've tried to create from user root with empty password and sail with password password but go access denied.
tried command line to run
docker-compose exec -u 0 "mariadb" mysql -usail -ppassword -e 'create database databaseName;'
but also got access denied.
You can do this by adding an additional volume in your docker-compose.yml file
volumes:
- 'sail-mariadb:/var/lib/mysql'
- ./docker/8.1/create-extra-database.sql:/docker-entrypoint-initdb.d/create-extra-database.sql
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
Then make sure to have the create-extra-database.sql in the proper directory. Like this:
Then add whatever mysql commands you'd like in that file. Here I'm adding an additional log database.
CREATE DATABASE IF NOT EXISTS log;
GRANT ALL PRIVILEGES ON `log`.* TO 'sail'#'%';
Make sure to delete the previous mysql docker container and volume. Then run sail up
i see you use mariadb
so type
sail mariadb
will open mariadb line command
type
create database name

Matrix Synapse and Riot migration

how can I migrate all my data and configuration for matrix synapse and Riot.Im installed on the system to another one VM ?
Can I backup and restore all the rooms (created with Riot.IM) , the chat logs and the users and migrate all the content to another machine ?
The old system is configured without using docker.
Thank you
Information
All the applications are decentralized and there will be configurations file which are holding your server and connection information, Remaining all the data is stores in the Database which you are using. So we have client in your case Riot , Matrix Synapse and Database(Migration)
Riot Migration
We have a configuration file named config.json (default) which has the URL's of your synapse server. While Migrating copy the values of the from your existing riot config file to your new riot config file.
Synapse Migration
Similar to the Riot there is a homeserver.yaml and conf.d/server_name.yaml files in matrix-synapse installation folder, which has all the configurations. Copy the contents from these files to new matrix files and you are done with client and interface, Let's get into Data Migration.
Database Migration
SQLITE3 to PostgreSQL follow the command
create dump file from sqlite
sqlite database .dump > /the/path/to/sqlite-dumpfile.sql
copy that sql dump file to PostgreSQL
/path/to/psql -d database -U username -W < /the/path/to/sqlite-dumpfile.sql
Old PostgreSQL to new PostgreSQL
Create a dump file as backup from older PostgreSQL
pg_dump dbname > outfile
Restore the data from this dump
psql dbname < infile
Using Database migration GUI tools such as Pentaho or dbsoft . Follow the dbsofts article
You can refer to element docs on migration, matrix docs and SQLite to PostgreSQL

How to allow creation of database triggers

When trying to install CiviCrm in Drupal 7 I get "Could not create a database trigger".
Using a standard ddev config.yml for drupal7.
A couple of solutions are suggested at https://civicrm.stackexchange.com/questions/2770/database-trigger-error-message but I am struggling to implement them within ddev.
RE Grant - When I try ddev exec mysql GRANT..... I get failed to execute command. When I ssh into a mysql shell to try to grant privileges I get access denied for user.
RE log_bin_trust_function_creators = 1. Where would I insert that?
Update 2019-01-25: I went to check this out after you created the issue and what I suggested was inadequate. As explained there, you need to do a little custom config. Create a .ddev/mysql/trigger.cnf with these contents:
[mysqld]
log_bin_trust_function_creators=on
And the next release of ddev (mid-February) will make this the default (PR). So please report your results there. I was able to install CiviCRM with this mysql config.
Original response: True but not adequate for triggers:
The db container root user has full privileges, so you can use mysql -uroot -proot ... to do what you need to do. You can do that inside the db container ddev ssh -s db or inside the web container ddev ssh or from the host using the info in ddev describe (but using root/root). (You can also use the root user to grant additional privileges to the db user, of course.)
If you know what privileges are required, we should add them to the db user, so please make an issue requesting what you need, because we'd like this to be easier for you.

Heroku app change: db migration (pg and MongoHQ)

I had and app on heroku
then I decided to create another app (on cedar stack which does not support stack:migrate).
How can I migrate databases PG and MongoHq?
Thanks!
You can migrate MongoHQ by logging into heroku and clicking on addons => mongohq. From the application, create a new user under Database Users named "backup" with a simple password. Below, my password was "temppw". Then click the Database Info tab for your connection information (host:port [flame.mongohq.com:27049] and dbname [appXXXXXX]). Then just call mongodump to get a backup.
mongodump -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw
This will make a local directory called "dump" containing your data. Verify it is there by loading it into a local db (just run mongorestore and look in your local mongo install) - because when you destroy your old app, it destroys the MongoDB (heroku also destroys your postgres db - so you should do this for that as well).
Anyway, do the same as above to your new application database, except use mongorestore.
mongorestore -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw dump/appXXXXXX
DO NOT JUST POINT THE ENVIRONMENT URLS. This is dangerous, because deleting your initial app will destroy all of your data.
I'm not sure about MongoHQ but as for PostgreSQL, you can use Heroku Taps to pull the data from the remote database to your local machine. You could then push it to the new app.
Alternatively you could change the environment variable DATABASE_URL of your new Cedar app to point to the database being used by the old app - assuming you're not using the shared database.
This last approach would also work for MongoHq.

Resources