Update env files and move to postgres
This commit is contained in:
parent
494d880771
commit
3a730fea36
|
@ -3,6 +3,8 @@
|
||||||
cache/
|
cache/
|
||||||
/photos_path
|
/photos_path
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
||||||
# docker
|
# docker
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copy this file to .env
|
||||||
|
|
||||||
NEO4J_URI=bolt://localhost:7687
|
NEO4J_URI=bolt://localhost:7687
|
||||||
NEO4J_USER=neo4j
|
NEO4J_USER=neo4j
|
||||||
NEO4J_PASSWORD=letmein
|
NEO4J_PASSWORD=letmein
|
6
api/.env
6
api/.env
|
@ -1,6 +0,0 @@
|
||||||
MYSQL_HOST=127.0.0.1:3306
|
|
||||||
MYSQL_DATABASE=photoview
|
|
||||||
MYSQL_USERNAME=photoview
|
|
||||||
MYSQL_PASSWORD=
|
|
||||||
|
|
||||||
API_PORT=4001
|
|
|
@ -2,30 +2,23 @@ package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
// Load mysql driver
|
// Load mysql driver
|
||||||
_ "github.com/go-sql-driver/mysql"
|
// _ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
|
// Load postgres driver
|
||||||
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupDatabase connects to the database using environment variables
|
// SetupDatabase connects to the database using environment variables
|
||||||
func SetupDatabase() *sql.DB {
|
func SetupDatabase() *sql.DB {
|
||||||
|
|
||||||
host := os.Getenv("MYSQL_HOST")
|
address := os.Getenv("POSTGRES_URL")
|
||||||
database := os.Getenv("MYSQL_DATABASE")
|
|
||||||
username := os.Getenv("MYSQL_USERNAME")
|
|
||||||
password := os.Getenv("MYSQL_PASSWORD")
|
|
||||||
|
|
||||||
if host == "" || database == "" || username == "" {
|
|
||||||
log.Fatalln("Database host, name and username are required")
|
|
||||||
}
|
|
||||||
|
|
||||||
address := fmt.Sprintf("%s:%s@tcp(%s)/%s", username, password, host, database)
|
|
||||||
log.Printf("Connecting to database: %s", address)
|
log.Printf("Connecting to database: %s", address)
|
||||||
|
|
||||||
db, err := sql.Open("mysql", address)
|
db, err := sql.Open("postgres", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not connect to database: %s\n", err.Error())
|
log.Fatalf("Could not connect to database: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Copy this file to .env
|
||||||
|
|
||||||
|
POSTGRES_URL=postgres://username:password@localhost/database?sslmode=disable
|
||||||
|
|
||||||
|
API_PORT=4001
|
|
@ -6,5 +6,6 @@ require (
|
||||||
github.com/99designs/gqlgen v0.10.2
|
github.com/99designs/gqlgen v0.10.2
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
|
github.com/lib/pq v1.3.0
|
||||||
github.com/vektah/gqlparser v1.2.0
|
github.com/vektah/gqlparser v1.2.0
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,8 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||||
|
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||||
|
|
Loading…
Reference in New Issue