Skip to content

Commit

Permalink
Improve database selection. (#42)
Browse files Browse the repository at this point in the history
* Improve database selection.

* Remove laravel references.

* Insert db logic to util function.
  • Loading branch information
reynoldsalec authored Mar 5, 2024
1 parent 3bb1db0 commit febef04
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-backdrop-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
leia-test:
- examples/backdrop-custom
- examples/backdrop-defaults
- examples/backdrop-downstreamer-1
- examples/backdrop-downstreamer-2
- examples/backdrop-export
- examples/backdrop-import
- examples/backdrop-init
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.2.1 - [March 4, 2024](https://github.com/lando/backdrop/releases/tag/v1.2.1)

### Fixes

* Improved `database` selection for purposes of `config` loading, fixes some `database` bootup issues when the `database` type is overriden downstream

## v1.2.0 - [February 24, 2024](https://github.com/lando/backdrop/releases/tag/v1.2.0)

### New Features
Expand Down
11 changes: 11 additions & 0 deletions examples/backdrop-downstreamer-1/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: backdrop-downstreamer-1
recipe: backdrop

services:
database:
type: mysql:8.0

# do not remove this
plugins:
"@lando/backdrop": ../..
"@lando/mysql": ../../node_modules/@lando/mysql
44 changes: 44 additions & 0 deletions examples/backdrop-downstreamer-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Backdrop Downstreamer Example

This example exists primarily to test the following documentation:

* [Backdrop Recipe](https://docs.lando.dev/backdrop/config.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should start up successfully
lando poweroff
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should be using mysql8
lando mysql -V | grep 8.0

# Should use the default database connection info
lando mysql -ubackdrop -pbackdrop backdrop -e quit

# Should use the defauly mysql8 config file
lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOBACKDROPMYSQL8CNF"
lando mysql -u root -e "show variables;" | grep innodb_lock_wait_timeout | grep 127
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
1 change: 1 addition & 0 deletions examples/backdrop-downstreamer-1/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULTS
1 change: 1 addition & 0 deletions examples/backdrop-downstreamer-1/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php phpinfo(); ?>
11 changes: 11 additions & 0 deletions examples/backdrop-downstreamer-2/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: backdrop-downstreamer-2
recipe: backdrop

services:
database:
type: backdrop-mysql:8.0

# do not remove this
plugins:
"@lando/backdrop": ../..
"@lando/mysql": ../../node_modules/@lando/mysql
44 changes: 44 additions & 0 deletions examples/backdrop-downstreamer-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Backdrop Downstreamer Example

This example exists primarily to test the following documentation:

* [Backdrop Recipe](https://docs.lando.dev/backdrop/config.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should start up successfully
lando poweroff
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should be using mysql8
lando mysql -V | grep 8.0

# Should use the default database connection info
lando mysql -ubackdrop -pbackdrop backdrop -e quit

# Should use the defauly mysql8 config file
lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOBACKDROPMYSQL8CNF"
lando mysql -u root -e "show variables;" | grep innodb_lock_wait_timeout | grep 127
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
1 change: 1 addition & 0 deletions examples/backdrop-downstreamer-2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULTS
1 change: 1 addition & 0 deletions examples/backdrop-downstreamer-2/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php phpinfo(); ?>
11 changes: 9 additions & 2 deletions utils/get-config-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
const _ = require('lodash');
const fs = require('fs');

/*
* Helper to get database type
*/
const getDatabaseType = options => {
return _.get(options, '_app.config.services.database.type', options.database) ?? 'mysql';
};

module.exports = options => {
// Get the viaconf
if (_.startsWith(options.via, 'nginx')) options.defaultFiles.vhosts = 'default.conf.tpl';

// Get the default db conf
const dbConfig = _.get(options, 'database', 'mysql');
const dbConfig = getDatabaseType(options);
const database = _.first(dbConfig.split(':'));
const version = _.last(dbConfig.split(':')).substring(0, 2);
if (database === 'mysql' || database === 'mariadb') {
if (database === 'backdrop-mysql' || database === 'mysql' || database === 'mariadb') {
if (version === '8.') {
options.defaultFiles.database = 'mysql8.cnf';
} else {
Expand Down

0 comments on commit febef04

Please sign in to comment.