Skip to content

Commit eb39056

Browse files
author
Gaetano Giunta
committed
add stack.sh; better links to adminer; better shell in worker; use prod sf by default; fix DatabaseSchemaManager.php
1 parent 8565737 commit eb39056

File tree

14 files changed

+241
-80
lines changed

14 files changed

+241
-80
lines changed

README.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ In the meantime, you can try out http://sqlfiddle.com/
3737

3838
* Docker-compose: version 1.10 or later
3939

40+
* Recommended: bash shell
41+
4042
* minimum RAM, CPU, Disk space: these have not been measured, but you probably want something better than a raspberry pi...
4143

4244

4345
## Quick Start
4446

47+
NB: if you have no bash shell interpreter on your host computer, scroll to the end for alternative instructions
48+
4549
### Installation
4650

47-
cd docker && touch containers.env.local && docker-compose build
51+
./bin/stack.sh build
4852

4953
*NB*: this will take a _long_time. Also, a fast, unmetered internet connection will help.
5054

@@ -59,39 +63,34 @@ the host computer, please change variables COMPOSE_WEB_LISTEN_PORT_HTTP and COMP
5963

6064
Example: executing the sql snippet `select current_date` in parallel on all databases:
6165

62-
cd docker && docker-compose up -d
63-
docker exec -ti db3v4l_worker su - db3v4l
64-
cd app
65-
66-
php bin/console db3v4l:sql:execute --sql='select current_date'
67-
68-
exit
69-
docker-compose stop
66+
./bin/stack.sh start
67+
./bin/stack.sh console db3v4l:sql:execute --sql='select current_date'
68+
./bin/stack.sh stop
7069

7170
If you have a bigger set of SQL commands to execute than it is practical to put in a command-line, you can save them
7271
to a file and then execute it in parallel on all databases:
7372

74-
php bin/console db3v4l:sql:execute --file=./shared/my_huge_script.sql
73+
./bin/stack.sh console db3v4l:sql:execute --file=./shared/my_huge_script.sql
7574

7675
*NB* to share files between the host computer and the container, put them in the `shared` folder.
7776

7877
*NB* you can also execute different sql commands based on database type by saving them to separate files. The `sql:execute`
7978
command does replace some tokens in the values of the `--file` option. Eg:
8079

81-
php bin/console db3v4l:sql:execute --file='./shared/test_{dbtype}.sql'
80+
./bin/stack.sh console db3v4l:sql:execute --file='./shared/test_{dbtype}.sql'
8281

83-
will look for files `test_mariadb.sql`, `test_mssql.sql`, `test_mysql.sql`, `test_postgresql.sql`, `test_sqlite.sql`
82+
will look for files `test_mariadb.sql`, `test_mssql.sql`, `test_mysql.sql`, `test_postgresql.sql`, `test_sqlite.sql`
8483

85-
From within the worker container, you can also list all available database instances:
84+
You can also list all available database instances:
8685

87-
php bin/console db3v4l:instance:list
86+
./bin/stack.sh console db3v4l:instance:list
8887

8988
As well as test connecting to them using the standard clients:
9089

91-
mysql -h mysql_5_5 -u 3v4l -p -e 'select current_date'
92-
psql -h postgresql_9_4 -U postgres -c 'select current_date'
93-
sqlcmd -S mssqlserver_2019_ga -U sa -Q "select GETDATE() as 'current_date'"
94-
sqlite3 /home/db3v4l/data/sqlite/3.27/3v4l.sqlite 'select current_date'
90+
./bin/stack.sh run mysql -h mysql_5_5 -u 3v4l -p -e 'select current_date'
91+
./bin/stack.sh run psql -h postgresql_9_4 -U postgres -c 'select current_date'
92+
./bin/stack.sh run sqlcmd -S mssqlserver_2019_ga -U sa -Q "select GETDATE() as 'current_date'"
93+
./bin/stack.sh run sqlite3 /home/db3v4l/data/sqlite/3.27/3v4l.sqlite 'select current_date'
9594

9695
The default password for those commands is '3v4l' for all databases except ms sql server, for which it is 3v4l3V4L.
9796

@@ -101,9 +100,9 @@ your browser is executing).
101100

102101
Last but not least, you have access to other command-line tools which can be useful in troubleshooting SQL queries:
103102

104-
./vendor/bin/highlight-query
105-
./vendor/bin/lint-query
106-
./vendor/bin/tokenize-query
103+
./vendor/bin/highlight-query
104+
./vendor/bin/lint-query
105+
./vendor/bin/tokenize-query
107106

108107

109108
## Details
@@ -155,6 +154,18 @@ After starting the containers via `docker-compose up -d`, you can:
155154
such as passwords
156155

157156

157+
## Alternative commands to stack.sh
158+
159+
./bin/stack.sh build => cd docker && touch containers.env.local && docker-compose build
160+
./bin/stack.sh start => cd docker && docker-compose up -d
161+
./bin/stack.sh shell => docker exec -ti db3v4l_worker su - db3v4l
162+
./bin/stack.sh stop => cd docker && docker-compose stop
163+
164+
./bin/stack.sh console ... =>
165+
docker exec -ti db3v4l_worker su - db3v4l
166+
php bin/console ...
167+
168+
158169
## Thanks
159170

160171
Many thanks to

app/.bash_profile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## CUSTOM environment configuration - added into the container by Docker build
2+
3+
# This file is executed for login shells.
4+
# Note: we force login shells when using builder.php both for entering the container and for executing scripts
5+
6+
# 1. execute .bashrc stuff for shells which are both login & interactive
7+
# (note that the debian .bashrc will exit immediately if non-interactive shell is found)
8+
if [ -f ~/.bashrc ]; then
9+
source ~/.bashrc
10+
fi
11+
12+
# If running interactively, don't do anything more - .bashrc has done everything
13+
case $- in
14+
*i*) return;;
15+
*) ;;
16+
esac

app/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
###> symfony/framework-bundle ###
1717
KERNEL_CLASS='Db3v4l\Kernel'
18-
APP_ENV=dev
18+
APP_ENV=prod
1919
APP_SECRET=74640ad5ec7f157b08ea25409c99f2e3
2020
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
2121
#TRUSTED_HOSTS='^localhost|example\.com$'

app/admin/adminer/plugins/login-servers-enhanced.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AdminerLoginServersEnhanced
2121
private $servers;
2222

2323
/** Set supported servers
24-
* @param array array(AdminerLoginServerEnhanced)
24+
* @param AdminerLoginServerEnhanced[] $servers
2525
*/
2626
public function __construct($servers)
2727
{
@@ -60,6 +60,21 @@ public function loginForm()
6060

6161
private function getTrServer()
6262
{
63+
// the urls with these params are generated by adminer. We transform them to use $_GET['server']
64+
if (isset($_GET["mssql"])) {
65+
$_GET['server'] = explode(':', $_GET["mssql"])[0];
66+
} elseif (isset($_GET["oracle"])) {
67+
$_GET['server'] = explode(':', $_GET["oracle"])[0];
68+
} elseif (isset($_GET["pgsql"])) {
69+
$_GET['server'] = explode(':', $_GET["pgsql"])[0];
70+
} elseif (isset($_GET["server"])) {
71+
$_GET['server'] = explode(':', $_GET["server"])[0];
72+
} elseif (isset($_GET["sqlite"])) {
73+
$_GET['server'] = explode(':', $_GET["sqlite"])[0];
74+
} else {
75+
$_GET['server'] = null;
76+
}
77+
6378
$html = '<tr><th>'.lang('Server').'<td>';
6479

6580
$html .= '<input type="hidden" name="auth[driver]" value="'.$this->servers[0]->driver.'">';
@@ -69,8 +84,8 @@ private function getTrServer()
6984
if (!$server instanceof AdminerLoginServerEnhanced) {
7085
continue;
7186
}
72-
// allow to start with a different db selected based on $_GET['db']
73-
$html .= $server->getOptionTag($key == @$_GET['server']);
87+
// allow to start with a different db selected based on $_GET['server']
88+
$html .= $server->getOptionTag($server->domain == $_GET['server']);
7489
}
7590
$html .= '</select>';
7691

app/admin/public/index.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ function buildServerList()
1111
$servers[$instance] = new AdminerLoginServerEnhanced(
1212
$def['host'].':'.$def['port'],
1313
$def['vendor'].' '.$def['version'],
14-
str_replace(array('mariadb', 'mysql', 'postgresql'), array('server', 'server', 'pgsql'), $def['vendor'])
14+
str_replace(
15+
array('mariadb', 'mysql', 'postgresql'),
16+
array('server', 'server', 'pgsql'),
17+
$def['vendor']
18+
)
1519
);
1620
}
1721
return $servers;
1822
}
1923

2024
function adminer_object()
2125
{
22-
2326
$pluginsDir = dirname(__DIR__).'/adminer/plugins/';
2427

2528
// required to run any plugin
@@ -36,7 +39,8 @@ function adminer_object()
3639
);
3740

3841
// customizations
39-
class AdminerCustomization extends AdminerPlugin {
42+
class AdminerCustomization extends AdminerPlugin
43+
{
4044
function name() {
4145
// custom name in title and heading
4246
return 'DB-3v4l Admin';

app/config/secrets/prod/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/src/Core/DatabaseSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getDropDatabaseQL($userName, $dbName = null)
7979
$dbName = $userName;
8080
}
8181

82-
$dbType = $this->getDbTypeFromDriver($this->databaseConfiguration['driver']);
82+
$dbType = $this->getDbType($this->databaseConfiguration);
8383

8484
switch ($dbType) {
8585
case 'mysql':
@@ -108,7 +108,7 @@ public function getDropDatabaseQL($userName, $dbName = null)
108108
*/
109109
public function getListDatabasesSQL()
110110
{
111-
$dbType = $this->getDbTypeFromDriver($this->databaseConfiguration['driver']);
111+
$dbType = $this->getDbType($this->databaseConfiguration);
112112

113113
switch ($dbType) {
114114
case 'mysql':

app/templates/Default/index.html.twig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
{% block page_content %}
66
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
77
{% block box_title %}
8-
Welcome to the best command-line SQL shell
8+
Welcome to the most promiscuous command-line SQL shell
99
{% endblock %}
1010
{% block box_body %}
1111
{% apply markdown_to_html %}
1212
DB-3v4l.org (leetspeak for database-eval) is a command-line tool that allows you to run SQL code on multiple database servers.
1313

14-
There are currently 19 server instances for you to test against.
14+
There are currently 19 server instances for you to test your queries on.
1515

16-
For every script you submit, this tool gives you back:
16+
For every query you submit, this tool gives you back:
1717
- Output (the selected data)
1818
- Performance (time and memory) of execution
1919

@@ -24,9 +24,8 @@
2424
```
2525
cd docker && docker-compose up -d
2626
docker exec -ti db3v4l_worker su - db3v4l
27-
cd app
2827

29-
php bin/console db3v4l:sql:execute --sql='select current_date'
28+
php bin/console db3v4l:sql:execute --sql='select current_date'
3029

3130
exit
3231
docker-compose stop

app/templates/Instance/list.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<tbody>
2020
{% for instance, config in instances %}
2121
{# @todo add prefilling of root username #}
22-
<tr><td>{{ instance }}</td><td>{{ config.vendor }}</td><td>{{ config.version }}</td><td><a href="/admin/?server={{ instance }}" class="fa fa-toolbox"></a></td></tr>
22+
<tr><td>{{ instance }}</td><td>{{ config.vendor }}</td><td>{{ config.version }}</td><td><a href="/admin/?server={% if config.host is defined %}{{ config.host }}{% if config.port is defined %}:{{ config.port }}{% endif %}{% endif %}" class="fa fa-toolbox"></a></td></tr>
2323
{% endfor %}
2424
</tbody>
2525
</table>

doc/TODO.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
- worker: some failures in (temp) db removal are not reported (eg on mysql, for non existing db).
2-
Are we leaving behind temp databases?
3-
41
- improve handling of character sets:
52
+ make sure we always create utf8 databases
63
+ make sure we always get back by default utf8 data from the clients
74

8-
- host: improve cli scripts:
9-
+ add a 'stack' script that simplifies building the stack and logging into it
10-
=> force usage of a random (or user-provided) pwd for db root account on startup
11-
+ also, add a 'console' script to transparently execute sf commands from the host
12-
+ add a script that removes images+logs+data
13-
+ move from bash to sh
14-
15-
- set default sf env to prod
16-
17-
- web gui improvements:
18-
+ keep icons visible when collapsing left menu
19-
+ add a logo
20-
215
- admin(er) improvements:
6+
+ can not connect to mariadb 5.5
227
+ sqllite not working in pre-filled list of databases (miss filename for root db)
238
+ add sql log file
249
+ add data dump capabilities
@@ -30,13 +15,7 @@
3015
+ add a separate sf console that only registers db3v4l commands
3116
+ either remove ./vendor/bin/doctrine-dbal or make it actually work
3217

33-
- worker+web: when listing instances, show the _real_ db version nr. (from a query, not config => ses how Adminer does it)
34-
35-
- worker: improve profile of 'db3v4l' account
36-
+ esp: add APP_ENV and APP_DEBUG env vars (via bootstrap.sh ?)
37-
+ start in correct dir automatically
38-
+ enable `ll` and `la` shell aliases
39-
+ use a colored shell prompt
18+
- worker: some failures in (temp) db removal are not reported (eg on mysql, for non existing db)?
4019

4120
- host: allow building/starting partial docker stack for speed and resources (eg. no oracle, no sqlserver, etc...)
4221
Being able to start a single 'db type' might also make sense in parallelization of tests on travis.
@@ -46,6 +25,20 @@
4625

4726
- add travis testing
4827

28+
- host: improve cli scripts:
29+
+ stack.sh: force usage of a random (or user-provided) pwd for db root account on startup
30+
+ add a script that removes docker images and containers (eg. docker-compose down)
31+
+ move from bash to sh
32+
33+
- web gui improvements:
34+
+ keep icons visible when collapsing left menu
35+
+ add a logo
36+
37+
- worker+web: when listing instances, show the _real_ db version nr. (from a query, not config => ses how Adminer does it)
38+
39+
- worker: improve profile of 'db3v4l' account
40+
+ use a colorful shell prompt
41+
4942
- worker: sanitize sql execution cmd:
5043
+ examine in detail and document the differences between running a command vs a file (eg. transaction usage)
5144
+ disallow execution of commands that are part of the db client instead of being sent to the server, such as eg. 'use db'

0 commit comments

Comments
 (0)