schultek / stormberry

Access your postgres database effortlessly from dart code.
https://pub.dev/packages/stormberry
MIT License
68 stars 17 forks source link

Problem with migration [BUG?] #32

Closed sorgfal closed 1 year ago

sorgfal commented 1 year ago

Thanks, the dart community has been waiting for a database tool for a long time. But I got a problem.

Enviroment: MacOS Postgres over docker compose. Proof of ip:

image

run_migration.sh

DB_HOST_ADDRESS=172.19.0.2
DB_PORT=5432
DB_NAME=todo_list_db
DB_USERNAME=postgres
DB_PASSWORD=password
echo $DB_HOST_ADDRESS
echo $DB_PORT
echo $DB_NAME
echo $DB_USERNAME
echo $DB_PASSWORD
dart run stormberry migrate -o=./migrations/  --db=$DB_NAME

script output

yona@MacBook-Air-Daniil todolistdemobackend % ./scripts/build_migrations.sh 
172.19.0.2
5432
todo_list_db
postgres
password
Database: connecting to todo_list_db at 127.0.0.1...
Error on connection: SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 51920
Database: retrying connecting...
SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 51921
#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682:35)
#1      _NativeSocket.connect (dart:io-patch/socket_patch.dart:948:12)
#2      _RawSocket.connect (dart:io-patch/socket_patch.dart:1815:26)
#3      RawSocket.connect (dart:io-patch/socket_patch.dart:21:23)
#4      Socket._connect (dart:io-patch/socket_patch.dart:2038:22)
#5      Socket.connect (dart:io/socket.dart:743:21)
#6      PostgreSQLConnection.open (package:postgres/src/connection.dart:188:32)
#7      Database._tryOpen (package:stormberry/src/core/database.dart:80:34)
<asynchronous suspension>
#8      MigrateCommand.run (package:stormberry/src/cli/runner.dart:115:5)
<asynchronous suspension>
#9      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#10     main (file:///Users/yona/.pub-cache/hosted/pub.dartlang.org/stormberry-0.9.2/bin/stormberry.dart:12:5)
<asynchronous suspension>

yona@MacBook-Air-Daniil todolistdemobackend % 

It looks like the migration tool can't see the environment variables.

Also i have feature request. Can we get tool for calling migration from code. I think it will useful.

schultek commented 1 year ago

Thanks.

I think in the script you have to export the env vars:

export DB_HOST_ADDRESS=172.19.0.2
...
dart run stormberry migrate -o=./migrations/

Btw when you specify the db name through the env var you dont need the cli argument.

Regarding the feature request: Can you make a proposal for this? Feel free to open a separate issue and describe what you are looking for.

sorgfal commented 1 year ago
  1. Thank you. My mistake. Tottaly forgot about export keyword.
  2. Yes, i will prepare proposal.