Skip to content

Commit

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

* Make sure we add dbConfig.

* Remove laravel references.

* Get rid of laravel reference.

* Correct doc comments.
  • Loading branch information
reynoldsalec committed Mar 5, 2024
1 parent 77895d7 commit c4ce096
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-wordpress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
leia-test:
- examples/wordpress-custom
- examples/wordpress-defaults
- examples/wordpress-downstreamer-1
- examples/wordpress-downstreamer-2
- examples/wordpress-export
- examples/wordpress-import
- examples/wordpress-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/wordpress/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 22, 2024](https://github.com/lando/wordpress/releases/tag/v1.2.0)

### New Features
Expand Down
14 changes: 11 additions & 3 deletions builders/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const getServiceConfig = (options, types = ['php', 'server', 'vhosts']) => {
return config;
};

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

// Tooling defaults
const toolingDefaults = {
'composer': {
Expand Down Expand Up @@ -163,11 +170,12 @@ const getConfigDefaults = 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');
// attempt to discover the database that is actually being used
// @NOTE: this will look to see if database is overridden
const dbConfig = getDatabaseType(options);
const database = _.first(dbConfig.split(':'));
const version = _.last(dbConfig.split(':')).substring(0, 2);
if (database === 'mysql' || database === 'mariadb') {
if (database === 'wordpress-mysql' || database === 'mysql' || database === 'mariadb') {
if (version === '8.') {
options.defaultFiles.database = 'mysql8.cnf';
} else {
Expand Down
11 changes: 11 additions & 0 deletions examples/wordpress-downstreamer-1/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: wordpress-downstreamer-1
recipe: wordpress

services:
database:
type: mysql:8.0

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

This example exists primarily to test the following documentation:

* [Wordpress Recipe](https://docs.lando.dev/wordpress/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 -uwordpress -pwordpress wordpress -e quit

# Should use the defauly mysql8 config file
lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOWORDPRESSMYSQL8CNF"
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/wordpress-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/wordpress-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/wordpress-downstreamer-2/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: wordpress-downstreamer-2
recipe: wordpress

services:
database:
type: wordpress-mysql:8.0

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

This example exists primarily to test the following documentation:

* [Wordpress Recipe](https://docs.lando.dev/wordpress/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 -uwordpress -pwordpress wordpress -e quit

# Should use the defauly mysql8 config file
lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOWORDPRESSMYSQL8CNF"
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/wordpress-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/wordpress-downstreamer-2/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php phpinfo(); ?>

0 comments on commit c4ce096

Please sign in to comment.