Ferry - 方便數據傳輸的ruby gem

jopen 10年前發布 | 13K 次閱讀 Ferry Ruby開發

Ferry是一個命令行工具rubygem設計用于Rails數據遷移和操作。

Ferry使用場景

查看示例:ferry_demo app or our GitHub pages site for guidance on using Ferry!

Rails數據遷移和操作的用例

  • 將數據導出成各種文件格式(.csv, .yml, .sql)
  • 從各種文件格式導入數據
  • 將數據遷移到第三方主機(Amazon S3, Oracle)
  • 數據遷移到不同的數據庫

安裝

Add this line to your Rails application's Gemfile:

gem 'ferry'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ferry

To view what Ferry can do for you just run:

$ ferry --help

導出

Ferry can export data from a database connected to a Rails app into a CSV or YAML file. We currently only support exporting of SQLite3, MySQL2, and PostgreSQL databases.

Run ferry --to_csv [environment] [table] in your Rails directory to export to csv:

$ ferry --to_csv production users

Running the above command will export the "users" table from the database connected to the "production" environment. A csv file populated with the "users" table data will be created at /db/csv/test/users.csv (the path will be created and if there is a users.csv it will be overwritten).

Run ferry --to_yaml [environment] [table] in your Rails directory to export to yaml:

$ ferry --to_yaml development users

Similarly, running the above command in the Rails directory will export the "users" table from the database connected to the "development" environment. A yaml file populated with the "users" table data will be created at /db/yaml/test/users.csv (the path will be created and if there is a users.csv it will be overwritten).

導入

Ferry can import a csv file of validated records into a table of a Rails-connected database. The csv file must:

  • Have headers that match field names of the table
  • Have values that meet the table's constraints (i.e. required fields, correct data types, unique PKs, etc.)

Run ferry --import [environment] [table] [file path] in your Rails directory to import a csv to a database table:

$ ferry --import development users db/csv/import_data.csv

Running the above command will import the import_data.csv to the "users" table in the "development" environment.

項目主頁:http://www.baiduhome.net/lib/view/home/1418608149948

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!