lets-go:4.3 setup a mariadb container and test data

This commit is contained in:
tamsin johnson 2024-01-24 22:56:58 -08:00
parent c20aa26084
commit fd34f7ba42
6 changed files with 56 additions and 0 deletions

4
snippetbox/.env Normal file
View File

@ -0,0 +1,4 @@
MARIADB_DATABASE=snippetbox
MARIADB_PASSWORD=dbpass
MARIADB_RANDOM_ROOT_PASSWORD=1
MARIADB_USER=snippetbox

View File

@ -0,0 +1,14 @@
USE snippetbox;
CREATE TABLE snippets (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
created DATETIME NOT NULL,
expires DATETIME NOT NULL
);
CREATE USER 'web'@'localhost';
GRANT SELECT, INSERT, UPDATE, DELETE ON snippetbox.* TO 'web'@'localhost' IDENTIFIED BY 'dbpass';
CREATE INDEX idx_snippets_created ON snippets(created);

View File

@ -0,0 +1,20 @@
INSERT INTO snippets (title, content, created, expires) VALUES (
'An old silent pond',
'An old silent pond...\nA frog jumps into the pont,\nsplash! Silence again.\n\n- Masuo Bashō',
UTC_TIMESTAMP(),
DATE_ADD(UTC_TIMESTAMP(), INTERVAL 365 DAY)
);
INSERT INTO snippets (title, content, created, expires) VALUES (
'Over the wintry forest',
'Over the wintry\nforest, winds howl in rage\nwith no leaves to blow.\n\n- Natsume Soseki',
UTC_TIMESTAMP(),
DATE_ADD(UTC_TIMESTAMP(), INTERVAL 365 DAY)
);
INSERT INTO snippets (title, content, created, expires) VALUES (
'First autumn morning',
'First autumn morning\nthe mirror I stare into\nshows my father''s face.\n\n- Murakami Kijo',
UTC_TIMESTAMP(),
DATE_ADD(UTC_TIMESTAMP(), INTERVAL 7 DAY)
);

View File

@ -0,0 +1,14 @@
version: "3.7"
services:
db:
image: mariadb
env_file: .env
volumes:
- mysql_data:/var/lib/mysql
- ./db/initdb.d:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
volumes:
mysql_data:

View File

@ -1,3 +1,5 @@
module snippetbox.chaosfem.tw
go 1.21.4
require github.com/go-sql-driver/mysql v1.7.1 // indirect

2
snippetbox/go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=