From ed28bf360b5c433c7d686d74af3ead9b9e6f8f4e Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 10 Aug 2021 15:48:44 -0400 Subject: [PATCH] Docker --- adminer/plugins-enabled/001-dump-json.php | 4 + adminer/plugins-enabled/002-edit-foreign.php | 4 + adminer/plugins-enabled/003-enum-option.php | 4 + adminer/plugins-enabled/004-json-column.php | 4 + adminer/plugins-enabled/database-hide.php | 8 ++ adminer/plugins-enabled/dump-markdown.php | 142 +++++++++++++++++++ adminer/plugins-enabled/foreign-keys.php | 86 +++++++++++ docker-compose.yml | 68 +++++++++ 8 files changed, 320 insertions(+) create mode 100644 adminer/plugins-enabled/001-dump-json.php create mode 100644 adminer/plugins-enabled/002-edit-foreign.php create mode 100644 adminer/plugins-enabled/003-enum-option.php create mode 100644 adminer/plugins-enabled/004-json-column.php create mode 100644 adminer/plugins-enabled/database-hide.php create mode 100644 adminer/plugins-enabled/dump-markdown.php create mode 100644 adminer/plugins-enabled/foreign-keys.php create mode 100644 docker-compose.yml diff --git a/adminer/plugins-enabled/001-dump-json.php b/adminer/plugins-enabled/001-dump-json.php new file mode 100644 index 0000000..e6d8eb9 --- /dev/null +++ b/adminer/plugins-enabled/001-dump-json.php @@ -0,0 +1,4 @@ + $l) ? substr($s, 0, $l) : $s.str_repeat($c, $l-strlen(utf8_decode($s))); + } + + function _map($array, $width, $c) { + foreach ($array as $k => &$v) $v = $this->_format_value($v, $width[$k], $c); + return $array; + } + + function _map_header($array) { + foreach ($array as $k => &$v) $v = $k; + return $array; + } + + function _map_mtable($array) { + foreach ($array as $k => &$v) $v = '-'; + return $array; + } + + function _markdown_row($row, $column_width, $separator, $filler) { + return implode($separator, $this->_map($row, $column_width, $filler)); + } + + function _markdown_table($rows, $column_width) { + $content = $this->_markdown_row($this->_map_header($rows[0]), $column_width, " | ", " ") . "\n"; + $content .= $this->_markdown_row($this->_map_mtable($rows[0]), $column_width, "-|-", "-") . "\n"; + foreach ($rows as $row) { + $content .= $this->_markdown_row($row, $column_width, " | ", " ") . "\n"; + } + return $content; + } + + function _bool($value) { + return $value == 1 ? 'Yes' : 'No'; + } + + function dumpFormat() { + return array($this->type => $this->format); + } + + function dumpDatabase($db) { + if ($_POST["format"] == $this->type) { + echo '# ' . $db . "\n\n"; + return true; + } + } + + /* export table structure */ + function dumpTable($table, $style, $is_view = false) { + if ($_POST["format"] == $this->type) { + echo '## ' . addcslashes($table, "\n\"\\") . "\n\n"; + + if ($style) { + echo "### table structure\n\n"; + + $field_rows = array(); + $field_width = (['Column name' => 11, 'Type' => 4, 'Comment' => 7, 'Null' => 4, 'AI' => 2]); + + foreach (fields($table) as $field) { + $new_row = [ + 'Column name' => $field['field'], + 'Type' => $field['full_type'], + 'Comment' => $field['comment'], + 'Null' => $this->_bool($field['null']), + 'AI' => $this->_bool($field['auto_increment']) + ]; + array_push($field_rows, $new_row); + foreach ($new_row as $key => $val) { + $field_width[$key] = max($field_width[$key], strlen(utf8_decode($new_row[$key]))); + } + } + echo $this->_markdown_table($field_rows, $field_width); + echo "\n"; + } + return true; + } + } + + /* export table data */ + function dumpData($table, $style, $query) { + if ($_POST["format"] == $this->type) { + + echo "### table data\n\n"; + + $connection = connection(); + $result = $connection->query($query, 1); + if ($result) { + $rn = 0; + $sample_rows = array(); + $column_width = array(); + + while ($row = $result->fetch_assoc()) { + switch(true) { + case $rn==0: + foreach ($row as $key => $val) { + $column_width[$key] = strlen(utf8_decode($key)); + } + case $rn<100: + $sample_rows[$rn]=$row; + foreach ($row as $key => $val) { + $column_width[$key] = max($column_width[$key], strlen(utf8_decode($row[$key]))); + } + break; + case $rn==100: + echo $this->_markdown_table($sample_rows, $column_width); + default: + echo $this->_markdown_row($row, $column_width, " | ", " ") . "\n"; + } + $rn++; + } + if ($rn<100) { + echo $this->_markdown_table($sample_rows, $column_width); + } + echo "\n"; + } + return true; + } + } + + function dumpHeaders($identifier, $multi_table = false) { + if ($_POST["format"] == $this->type) { + header("Content-Type: text/text; charset=utf-8"); + return "md"; + } + } +} diff --git a/adminer/plugins-enabled/foreign-keys.php b/adminer/plugins-enabled/foreign-keys.php new file mode 100644 index 0000000..4af7adb --- /dev/null +++ b/adminer/plugins-enabled/foreign-keys.php @@ -0,0 +1,86 @@ + + > + document.addEventListener("DOMContentLoaded", function() + { + collapsable = document.getElementsByClassName('collapsable') + + for (item of collapsable) { + item.addEventListener('click', function () { + moreDiv = this.parentElement.getElementsByClassName('fk-more')[0] + + if (moreDiv.classList.contains('hidden')) { + moreDiv.classList.remove('hidden') + this.innerHTML = " [less]" + } else { + moreDiv.classList.add('hidden') + this.innerHTML = " [more]" + } + + }) + } + }) + + + query('SELECT DATABASE() AS db;')->fetch_assoc(); + $result = $connection->query(sprintf('SELECT TABLE_NAME,COLUMN_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = \'%s\' AND CONSTRAINT_SCHEMA = \'%s\';', $tableName, $database['db'])); + + $backwardKeys = []; + $i = 0; + + if ($result) { + while ($row = $result->fetch_assoc()) { + $backwardKeys[$row['TABLE_NAME'] . $i] = [ + 'tableName' => $row['TABLE_NAME'], + 'columnName' =>$row['COLUMN_NAME'], + 'referencedColumnName' =>$row['REFERENCED_COLUMN_NAME'], + ]; + $i++; + } + } + + ksort($backwardKeys); + + return $backwardKeys; + } + + function backwardKeysPrint($backwardKeys, $row) { + $iterator = 0; + + foreach ($backwardKeys as $backwardKey) { + $iterator++; + $whereLink = where_link(1, $backwardKey['columnName'], $row[$backwardKey['referencedColumnName']]); + $link = sprintf('select=%s%s', $backwardKey['tableName'], $whereLink); + + if ($iterator === 2) { + echo ''; + } + } + + echo ''; + } +} + +return new AdminerForeignKeys(); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7fa8dc3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,68 @@ +version: '3' + +services: + backend-proxy: + container_name: backend_proxy + image: nginx + volumes: + - ./api/:/app/ + - ./api/nginx.conf:/etc/nginx/conf.d/default.conf + - ./logs/api/:/var/log/nginx/ + restart: unless-stopped + ports: + - 8081:80 + depends_on: + - backend + backend: + container_name: backend + image: php + build: + context: ./api + dockerfile: PHP.Dockerfile + env_file: .db.env + volumes: + - ./api/:/app/ + depends_on: + - db + + frontend-proxy: + container_name: frontend_proxy + image: nginx + volumes: + - ./ui/:/app/ + - ./ui/nginx.conf:/etc/nginx/conf.d/default.conf + - ./logs/ui/:/var/log/nginx/ + restart: unless-stopped + ports: + - 8080:80 + depends_on: + - frontend + frontend: + container_name: frontend + image: php:ui + build: + context: ./ui + dockerfile: PHP.Dockerfile + env_file: .ui.env + volumes: + - ./ui/:/app/ + + db: + image: mariadb + volumes: + - database:/var/lib/mysql + env_file: .db.env + adminer: + image: adminer + environment: + ADMINER_PLUGINS: "dump-json edit-foreign enum-option json-column" + ADMINER_DESIGN: "dracula" + volumes: + - ./adminer/plugins-enabled/:/var/www/html/plugins-enabled/ + ports: + - 8082:8080 + depends_on: + - db + +volumes: + database: