Skip to content

Commit

Permalink
improve database selection
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Feb 29, 2024
1 parent 7dc70ce commit 8975218
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 9 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/pr-laravel-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ jobs:
node-version:
- '18'
leia-test:
- examples/laravel-init
- examples/7.1
- examples/7.2
- examples/laravel-custom
- examples/laravel-downstreamer-1
- examples/laravel-downstreamer-2
- examples/laravel-defaults
- examples/laravel-export
- examples/laravel-import
- examples/laravel-init
- examples/laravel-mysql8
- examples/laravel-nginx
- examples/7.1
- examples/7.2

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

## v1.3.1 - [February 29, 2024](https://github.com/lando/laravel/releases/tag/v1.3.1)

### Fixes

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

## v1.3.0 - [February 27, 2024](https://github.com/lando/laravel/releases/tag/v1.3.0)

### New Features
Expand Down Expand Up @@ -25,7 +32,7 @@
* Fixed issue with missing proxy URLs.

## v1.0.0 - [December 7, 2023](https://github.com/lando/laravel/releases/tag/v1.0.0)

* Dialed fully for `lando update`

## v0.9.0 - [July 3, 2023](https://github.com/lando/laravel/releases/tag/v0.9.0)
Expand Down
15 changes: 12 additions & 3 deletions builders/laravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const getCache = cache => {
}
};

/*
* 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 @@ -105,11 +112,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 === 'laravel-mysql' || database === 'mysql' || database === 'mariadb') {
if (version === '8.') {
options.defaultFiles.database = 'mysql8.cnf';
} else {
Expand Down Expand Up @@ -243,6 +251,7 @@ module.exports = {
options.defaultFiles = _.merge({}, getConfigDefaults(_.cloneDeep(options)), options.defaultFiles);
options.services = _.merge({}, getServices(options), options.services);
options.tooling = _.merge({}, getTooling(options), options.tooling);

// Add in artisan tooling
// @NOTE: does artisan always live one up of the webroot?
options.tooling.artisan = {
Expand Down
Empty file removed examples/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion examples/.lando.upstream.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
plugins:
"@lando/laravel": ./../../../
"@lando/laravel": ../../..
11 changes: 11 additions & 0 deletions examples/laravel-downstreamer-1/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: laravel-downstreamer-1
recipe: laravel

services:
database:
type: mysql:8.0

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

This example exists primarily to test the following documentation:

* [Laravel Recipe](https://docs.lando.dev/laravel/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 -ularavel -plaravel laravel -e quit

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

services:
database:
type: laravel-mysql:8.0

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

This example exists primarily to test the following documentation:

* [Laravel Recipe](https://docs.lando.dev/laravel/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 -ularavel -plaravel laravel -e quit

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8975218

Please sign in to comment.