-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
se agregan nueva forma de administrar secrets, automatizacion a traves de Makefile, migraciones para bases de datos
- Loading branch information
Showing
19 changed files
with
135 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
HOST_SERVER= | ||
PORT_SERVER= | ||
DB_HOST= | ||
DB_PORT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_NAME= | ||
MARIADB_URL_0= | ||
MARIADB_URL_1= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
include .env | ||
|
||
run: | ||
go run main.go | ||
|
||
database-up: | ||
docker run \ | ||
-d \ | ||
--name mariaDB \ | ||
-p 3306:3306 \ | ||
-e MARIADB_ROOT_PASSWORD=${DB_PASSWORD} \ | ||
-e MARIADB_DATABASE=${DB_NAME} \ | ||
mariadb:10.7.4 | ||
database-down: | ||
docker rm -f mariaDB | ||
|
||
|
||
start-db: | ||
make database-up | ||
echo Espere unos segundos mientras se levanta la instancia | ||
sleep 15 | ||
make migrate-db | ||
|
||
|
||
migrate-db: | ||
migrate -path database/migrations/ -database ${MARIADB_URL} up | ||
|
||
migrate-db-rollback: | ||
migrate -path database/migrations/ -database ${MARIADB_URL} down | ||
|
||
tests: | ||
go test -v ./... | ||
|
||
# TO_DO: | ||
# 1.- refactoizar star-db | ||
# 2.- refactorizar sentencias migrate down | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS USERS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
create table USERS( | ||
id int not null auto_increment, | ||
email varchar(255) not null, | ||
name varchar(255) not null, | ||
password varchar(255) not null, | ||
primary key(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS PRODUCTS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create table PRODUCTS( | ||
id int not null auto_increment, | ||
name varchar(255) not null, | ||
description varchar(255) not null, | ||
price float not null, | ||
created_by int not null, | ||
primary key (id), | ||
foreign key (created_by) references USERS(id) | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS ROLES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
create table ROLES( | ||
id int not null auto_increment, | ||
name varchar(255) not null, | ||
primary key(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS USERS_ROLES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
create table USERS_ROLES( | ||
id int not null auto_increment, | ||
user_id int not null, | ||
role_id int not null, | ||
primary key (id), | ||
foreign key (user_id) references USERS(id), | ||
foreign key (role_id) references ROLES(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE ROLES DROP (id, name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
INSERT INTO ROLES (id, name) | ||
VALUES | ||
(1, 'admin'), | ||
(2, 'seller'), | ||
(3, 'customer'); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
package settings | ||
|
||
import ( | ||
_ "embed" | ||
"log" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
//go:embed settings.yml | ||
var settingsFile []byte | ||
|
||
type DatabaseConfig struct { | ||
Host string `yaml:"host"` | ||
Port int `yaml:"port"` | ||
User string `yaml:"user"` | ||
Password string `yaml:"password"` | ||
Name string `yaml:"name"` | ||
Host string `string:"host"` | ||
Port string `string:"port"` | ||
User string `string:"user"` | ||
Password string `string:"password"` | ||
Name string `string:"name"` | ||
} | ||
|
||
type Settings struct { | ||
Host string `yaml:"host"` | ||
Port string `yaml:"port"` | ||
DB DatabaseConfig `yaml:"database"` | ||
Host string `string:"host"` | ||
Port string `int64:"port"` | ||
DB DatabaseConfig `string:"database"` | ||
} | ||
|
||
func New() (*Settings, error) { | ||
var s Settings | ||
|
||
err := yaml.Unmarshal(settingsFile, &s) | ||
func init() { | ||
err := godotenv.Load(".env") | ||
if err != nil { | ||
return nil, err | ||
log.Fatal("Error loading .env") | ||
} | ||
} | ||
|
||
func New() *Settings { | ||
dbConf := DatabaseConfig{ | ||
Host: os.Getenv("D_HOST"), | ||
Port: os.Getenv("DB_PORT"), | ||
User: os.Getenv("DB_USER"), | ||
Password: os.Getenv("DB_PASSWORD"), | ||
Name: os.Getenv("DB_NAME"), | ||
} | ||
s := Settings{ | ||
Host: os.Getenv("HOST_SERVER"), | ||
Port: os.Getenv("PORT_SERVER"), | ||
DB: dbConf, | ||
} | ||
return &s, nil | ||
return &s | ||
} |