forked from DATA-DOG/go-txdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (42 loc) · 1.32 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
define MYSQL_SQL
CREATE TABLE users (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL,
username VARCHAR(32) NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uniq_email (email)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
endef
define PSQL_SQL
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(32) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL
);
endef
export MYSQL_SQL
MYSQL := "$$MYSQL_SQL"
export PSQL_SQL
PSQL := "$$PSQL_SQL"
INSERTS := "INSERT INTO users (username, email) VALUES ('gopher', 'gopher@go.com'), ('john', 'john@doe.com'), ('jane', 'jane@doe.com');"
MYSQLCMD=mysql
ifndef CI
MYSQLCMD=docker-compose exec mysql mysql
endif
PSQLCMD=psql
ifndef CI
PSQLCMD=docker-compose exec postgres psql
endif
test: mysql psql
@go test -race -tags "mysql psql"
mysql:
@$(MYSQLCMD) -h localhost -u root -e 'DROP DATABASE IF EXISTS txdb_test'
@$(MYSQLCMD) -h localhost -u root -e 'CREATE DATABASE txdb_test'
@$(MYSQLCMD) -h localhost -u root txdb_test -e $(MYSQL)
@$(MYSQLCMD) -h localhost -u root txdb_test -e $(INSERTS)
psql:
@$(PSQLCMD) -U postgres -c 'DROP DATABASE IF EXISTS txdb_test'
@$(PSQLCMD) -U postgres -c 'CREATE DATABASE txdb_test'
@$(PSQLCMD) -U postgres txdb_test -c $(PSQL)
@$(PSQLCMD) -U postgres txdb_test -c $(INSERTS)
.PHONY: test mysql psql