diff --git a/.gitignore b/.gitignore index 32e49c21..be2659b5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ cache/ /photos_path +.env + # docker docker-compose.yml diff --git a/api-node-old/.env b/api-node-old/example.env similarity index 88% rename from api-node-old/.env rename to api-node-old/example.env index 0d946d18..38ff9e86 100644 --- a/api-node-old/.env +++ b/api-node-old/example.env @@ -1,3 +1,5 @@ +# Copy this file to .env + NEO4J_URI=bolt://localhost:7687 NEO4J_USER=neo4j NEO4J_PASSWORD=letmein diff --git a/api/.env b/api/.env deleted file mode 100644 index 456cdec7..00000000 --- a/api/.env +++ /dev/null @@ -1,6 +0,0 @@ -MYSQL_HOST=127.0.0.1:3306 -MYSQL_DATABASE=photoview -MYSQL_USERNAME=photoview -MYSQL_PASSWORD= - -API_PORT=4001 \ No newline at end of file diff --git a/api/database/mysql.go b/api/database/mysql.go index a602bd0d..a9466177 100644 --- a/api/database/mysql.go +++ b/api/database/mysql.go @@ -2,30 +2,23 @@ package database import ( "database/sql" - "fmt" "log" "os" // 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 func SetupDatabase() *sql.DB { - host := os.Getenv("MYSQL_HOST") - 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) + address := os.Getenv("POSTGRES_URL") log.Printf("Connecting to database: %s", address) - db, err := sql.Open("mysql", address) + db, err := sql.Open("postgres", address) if err != nil { log.Fatalf("Could not connect to database: %s\n", err.Error()) } diff --git a/api/example.env b/api/example.env new file mode 100644 index 00000000..77a7129a --- /dev/null +++ b/api/example.env @@ -0,0 +1,5 @@ +# Copy this file to .env + +POSTGRES_URL=postgres://username:password@localhost/database?sslmode=disable + +API_PORT=4001 \ No newline at end of file diff --git a/api/go.mod b/api/go.mod index be8a10c9..737e031b 100644 --- a/api/go.mod +++ b/api/go.mod @@ -6,5 +6,6 @@ require ( github.com/99designs/gqlgen v0.10.2 github.com/go-sql-driver/mysql v1.5.0 github.com/joho/godotenv v1.3.0 + github.com/lib/pq v1.3.0 github.com/vektah/gqlparser v1.2.0 ) diff --git a/api/go.sum b/api/go.sum index 37f7ce90..37ad3c66 100644 --- a/api/go.sum +++ b/api/go.sum @@ -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/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/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/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=