golang-migrate / migrate

Database migrations. CLI and Golang library.
Other
15.44k stars 1.4k forks source link

Psql can`t connect migrate with my db #823

Open Vsevosemnog opened 2 years ago

Vsevosemnog commented 2 years ago

Describe the Bug I read the tutorial about how to connect and use migrate with my postgresql db. But when i use "migrate create" command migration files are empty

Steps to Reproduce Steps to reproduce the behavior:

  1. I execute export with my postgres user, his password, and db service_users image
  2. the output files are empty
  3. there`s no any record about my migrate creation attempt in postgresql logs

Expected Behavior There should be any evidence, that i use migrate program with my db. Any record in postgresql log file, any data in output files. it looks like i`ve not even connected with my db.

Migrate Version e.g. v4.15.2 Obtained by running: migrate -version

Loaded Source Drivers Source drivers: s3, bitbucket, github-ee, gitlab, go-bindata, godoc-vfs, github, gcs, file

Loaded Database Drivers Database drivers: stub, cassandra, firebird, neo4j, postgres, cockroach, mysql, clickhouse, cockroachdb, crdb-postgres, postgresql, redshift, spanner, sqlserver, firebirdsql, mongodb, mongodb+srv, pgx

Go Version go version go1.19.2 linux/amd6

Stacktrace Please provide if available

Additional context Please, help me to connect to my db with this program

bengesoff commented 2 years ago

You'll want to look into the migrate up command to actually apply the migrations - the create command just creates the files for you to populate

Vsevosemnog commented 2 years ago

No no no!) I would like to create sql files with content of creation scripts for my database. In order to do it one should use migrate create

migrate up is used for applying migrations to my db, i don`t need it right now

bengesoff commented 2 years ago

@EightLegs makes sense - in that case I think you need a different tool as this one is mainly good for creating your schema from scratch, rather than exporting an existing schema into migration scripts :)

Vsevosemnog commented 2 years ago

I need some help.

Have service_users db there i have service_users schema. I need to make a sql-file migration of this schema

am i doing this right?:

export POSTGRESQL_URL='postgres://postgres:@localhost:5432/service_users?sslmode=disable'

migrate create -ext sql -seq create_service_users_schema

After these commands the output files are empty.

How should i create migration?

drev74 commented 1 year ago

@Vsevosemnog That's an expected behavior. Migration create adds an empty numbered up and down files, which you need to fill with actual SQL commands