Skip to content

Commit 9abfc52

Browse files
committed
Add database definition
1 parent 61de2b9 commit 9abfc52

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The solution has to meet some requirements, which I didn'd found in the amount o
1515
* configuration of hosts and domain allowed to update
1616
* items like access keys, hosts, domains should not be hard-coded to keep flexible
1717

18-
It would have been easy to write a PHP script to handle the HTTP request, read and write database items and so on. But wait - when using PHP (or Perl, or Python...) in a Docker image, the image has to contain the whole bunch of runtime infrastructure like a webserver to handle the requests (when not using the "development" webserver integrated in PHP), PHP-FPM and the script itself. In my opinion this was exaggerated for this small task.
18+
It would have been easy to write a PHP script to handle the HTTP request, read and write database items and so on. But wait - when using PHP (or Perl, or Python...) in a Docker image, the image has to contain the whole bunch of runtime infrastructure like a webserver to handle the requests (when not using the "development" webserver integrated in PHP), PHP-FPM and the script itself. In my opinion this was exaggerated for this small task.
1919

2020
Since I wanted to deal with Golang for quite some time, this task was the perfect way to start. So I created the dynpower server module which handles the HTTP request and updates the database after checking the permissions. After this was running, I thought that would be a nice add-on to manage the configuration by a CLI tool. So dynpower-cli was written, it can list, add and delete domain and host entries.
2121

@@ -26,11 +26,17 @@ And thanks to the static binding of Go binaries and Docker multi-stage build, th
2626
* PowerDNS Authoritative Server with MySQL/MariaDB backend
2727
* access to PowerDNS database server
2828

29+
Dynpower needs a MySQL/MariaDB database to store domain and host data. So it's necessary to create a database with its access data at first. See dynpower.sql for the table definition.
30+
31+
If you're using the Docker image of MariaDB, you can place the dump file dynpower.sql in any directory which has to be mounted into the container. When starting the container, MariaDB executes files with extensions .sh, .sql and .sql.gz and creates the corresponding tables. See example in the docker-compose file below.
32+
33+
If you don't use Docker, please create a database and add a user with its grant permissions, so it is able to add and modify items. Then just import dynpower.sql to the database (e.g. ```mysql dynpower < ./sql/dynpower.sql```)
34+
2935
## Usage
3036

3137
It is recommended to use the dynpower Docker image. It comes with dynpower running as server and the dynpower CLI to manage its database entries.
3238

33-
Coming soon, I promise! Sorry, I'm ugly slow in writing this kind of documentation. ;-)
39+
Coming soon, I promise! Sorry, I'm terrible slow in writing this kind of documentation. ;-)
3440

3541
## Status
3642

sql/dynpower.sql

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
CREATE TABLE `domains` (
4+
`id` INT(11) NOT NULL AUTO_INCREMENT,
5+
`domainname` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8_general_ci',
6+
`access_key` VARCHAR(256) NOT NULL DEFAULT '' COLLATE 'utf8_general_ci',
7+
`dt_created` DATETIME NOT NULL,
8+
`dt_updated` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
9+
PRIMARY KEY (`id`) USING BTREE,
10+
UNIQUE INDEX `domainname` (`domainname`) USING BTREE
11+
)
12+
COLLATE='utf8_general_ci'
13+
ENGINE=InnoDB
14+
;
15+
16+
CREATE TABLE `dynrecords` (
17+
`id` INT(11) NOT NULL AUTO_INCREMENT,
18+
`domain_id` INT(11) NOT NULL DEFAULT '0',
19+
`hostname` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8_general_ci',
20+
`dt_created` DATETIME NOT NULL,
21+
`dt_updated` DATETIME NOT NULL,
22+
`host_updated` DATETIME NOT NULL,
23+
PRIMARY KEY (`id`) USING BTREE,
24+
UNIQUE INDEX `hostname` (`hostname`, `domain_id`) USING BTREE,
25+
INDEX `domain_id` (`domain_id`) USING BTREE
26+
)
27+
COLLATE='utf8_general_ci'
28+
ENGINE=InnoDB
29+
;
30+

0 commit comments

Comments
 (0)