diff --git a/Containerfile.utils b/Containerfile.utils index 763c449..e9f4bba 100644 --- a/Containerfile.utils +++ b/Containerfile.utils @@ -2,3 +2,4 @@ FROM docker.io/library/php:cli RUN docker-php-ext-install mysqli bcmath COPY ./utils/* /opt/ +COPY ./data_init/*.sql /opt/init/init.sql diff --git a/create_db.sh b/create_db.sh new file mode 100644 index 0000000..9a27b62 --- /dev/null +++ b/create_db.sh @@ -0,0 +1,2 @@ +podman run --network tor -it --env MYSQL_USER=root --env MYSQL_PASSWD=my-secret-pw --env MYSQL_DATABASE=exmple-database --env MARIADB_ROOT_PASSWORD=my-secret-pw -e MYSQL_HOST=some-mariadb -e MYSQL_DB=sunders -e CAMERA_USER=cam -e CAMERA_USER_PASSWD=asdf1234 -e CAMERA_SELECT_USER=cam -e CAMERA_SELECT_USER_PASSWD=asdf1234 localhost/sunders-utils:latest php /opt/create_db.php +podman run --network tor -it --env MYSQL_USER=root --env MYSQL_PASSWD=my-secret-pw --env MYSQL_DATABASE=exmple-database --env MARIADB_ROOT_PASSWORD=my-secret-pw -e MYSQL_HOST=some-mariadb -e MYSQL_DB=sunders -e CAMERA_USER=cam -e CAMERA_USER_PASSWD=asdf1234 -e CAMERA_SELECT_USER=cam -e CAMERA_SELECT_USER_PASSWD=asdf1234 localhost/sunders-data_init:latest \ No newline at end of file diff --git a/utils/create_db.php b/utils/init_db.php similarity index 86% rename from utils/create_db.php rename to utils/init_db.php index 9643699..90d6978 100644 --- a/utils/create_db.php +++ b/utils/init_db.php @@ -72,5 +72,19 @@ $conn->query("INSERT INTO sync_state (k, v) VALUES ('sequenceNumber', '0');"); echo "Database, users, and tables created successfully.\n"; +$result = $conn -> query("SELECT * FROM position limit 10"); + +$table_count = $result -> num_rows; + +printf("Result set has %d rows.\n", $table_count); +if ($table_count == 0){ +$location = "/opt/init/init.sql"; + +$commands = file_get_contents($location); +$conn->multi_query($commands); +echo "Inserted data.\n"; +} + + $conn->close(); ?>