fix: dockerfile & mariadb database

This commit is contained in:
Liangzhao Che 2023-05-12 21:46:48 +08:00
parent 7862701a26
commit 1a1fc59b10
4 changed files with 9 additions and 8 deletions

View File

@ -4,6 +4,9 @@ FROM golang:1.20 AS api
# Set working directory. # Set working directory.
WORKDIR /compiler WORKDIR /compiler
# Env GOPROY
ENV GOPROXY="https://proxy.golang.com.cn,direct"
# Copy dependency locks so we can cache. # Copy dependency locks so we can cache.
COPY go.mod go.sum ./ COPY go.mod go.sum ./

View File

@ -27,6 +27,8 @@ services:
- ./scripts/billMigrations.sql:/docker-entrypoint-initdb.d/1.sql - ./scripts/billMigrations.sql:/docker-entrypoint-initdb.d/1.sql
expose: expose:
- 3306 - 3306
ports:
- 3306:3306
environment: environment:
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=true - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=true
networks: networks:

View File

@ -8,7 +8,7 @@ import (
// This function is used to connect to MariaDB. // This function is used to connect to MariaDB.
func ConnectToMariaDB() (*sql.DB, error) { func ConnectToMariaDB() (*sql.DB, error) {
// Connect to MariaDB. // Connect to MariaDB.
db, err := sql.Open("mysql", "root:@tcp(mariadb:3306)/fiber_dmca") db, err := sql.Open("mysql", "root:@tcp(mariadb:3306)/bill")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,16 +4,14 @@ USE bill;
create table Bills create table Bills
( (
id int auto_increment id int auto_increment primary key,
primary key,
type varchar(15) not null, type varchar(15) not null,
date varchar(15) not null, date varchar(15) not null,
money varchar(900) null, money varchar(900) null,
cls varchar(900) null, cls varchar(900) null,
label varchar(900) null, label varchar(900) null,
options varchar(900) null options varchar(900) null
) );
charset = utf8mb4;
INSERT INTO bill.Bills (id, type, date, money, cls, label, options) INSERT INTO bill.Bills (id, type, date, money, cls, label, options)
VALUES (3341, 'INCOME', '2022-09-01', '8.5', '交通', '打的', ''); VALUES (3341, 'INCOME', '2022-09-01', '8.5', '交通', '打的', '');
@ -75,5 +73,3 @@ INSERT INTO bill.Bills (id, type, date, money, cls, label, options)
VALUES (3369, 'INCOME', '2022-07-07', '1.6', '交通', '公交', ''); VALUES (3369, 'INCOME', '2022-07-07', '1.6', '交通', '公交', '');
INSERT INTO bill.Bills (id, type, date, money, cls, label, options) INSERT INTO bill.Bills (id, type, date, money, cls, label, options)
VALUES (3370, 'INCOME', '2022-07-07', '9.0', '餐饮', '晚餐', ''); VALUES (3370, 'INCOME', '2022-07-07', '9.0', '餐饮', '晚餐', '');
INSERT INTO bill.Bills (id, type, date, money, cls, label, options)
VALUES (3371, 'INCOME', '2022-07-07', '5.5', '餐饮', '晚餐', '');