lets-go:4.3 setup a mariadb container and test data
This commit is contained in:
parent
c20aa26084
commit
fd34f7ba42
4
snippetbox/.env
Normal file
4
snippetbox/.env
Normal file
@ -0,0 +1,4 @@
|
||||
MARIADB_DATABASE=snippetbox
|
||||
MARIADB_PASSWORD=dbpass
|
||||
MARIADB_RANDOM_ROOT_PASSWORD=1
|
||||
MARIADB_USER=snippetbox
|
14
snippetbox/db/initdb.d/init.sql
Normal file
14
snippetbox/db/initdb.d/init.sql
Normal 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);
|
20
snippetbox/db/initdb.d/seed.sql
Normal file
20
snippetbox/db/initdb.d/seed.sql
Normal 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)
|
||||
);
|
14
snippetbox/docker-compose.yml
Normal file
14
snippetbox/docker-compose.yml
Normal 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:
|
@ -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
2
snippetbox/go.sum
Normal 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=
|
Loading…
Reference in New Issue
Block a user