23prime / db-csv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

db-csv

Import/Export DB table <-> CSV file.

Usage

Prepare

Install dependecies.

bundle config set path vendor/bundle
bundle install

Make .env and add DB_URL.

e.g.

DB_URL='postgres://<user>:<password>@<host>:<port>/<DB>'

DB table -> CSV file

bundle exec ruby src/db2csv.rb <table name>

If the table under a schema:

bundle exec ruby src/db2csv.rb <schema name>.<table name>

CSV file -> DB table

bundle exec ruby src/csv2db.rb <table name>

If the table under a schema:

bundle exec ruby src/csv2db.rb <schema name>.<table name>

Sync mode

If delete all and insert, add --sync option:

bundle exec ruby src/db2csv.rb <table name> --sync
bundle exec ruby src/csv2db.rb <table name> --sync

Note

CSV file must include column names.
And, exported CSV file include column names.

About


Languages

Language:Ruby 100.0%