csv_fast_importer 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1c6850b0ee75facc689b0992b21b3a3f94918bc9
4
- data.tar.gz: 19d416bfb8f7c61f56bfab8906e25adecf329ba8
2
+ SHA256:
3
+ metadata.gz: e64fb873391ad1bac7f05bf0bcefc26f0482d0917b71244e7388a19cd866b6cb
4
+ data.tar.gz: 6db4589951a6256be1b4334c0791cde38b10f4e87974bfbf85835ed39c01c061
5
5
  SHA512:
6
- metadata.gz: f5c35806af277b60c034b04f938dcf2faca4f9433a9194c985d098d5866230a58c07e9de678e69219d90097c0cbaac5fd9eb89d271936e8f35adf7c1121ac8e0
7
- data.tar.gz: cd058154e47b07196e6ad1448eab4e40ae9e452cba095f383bf4589615139f290decf223f966b19e7de90635dc7c4d8cf87b5836b4ff62f9a04d16a139d170ca
6
+ metadata.gz: 1d2ecf83bebef80e492e9799b4c2345c9b0a5e8c6a645c219a9acb2ed0012263ebf1322baa8ede53c9dc6390e6fb3846c9737979259957f1d2cc779ab654282e
7
+ data.tar.gz: 33ad1e337b5f4c649d86d96bb8a6f803168009719c47484dc76681e7dc70f6acb538c6f1a694e7f8939bc2ff20a2705bf5a0c08c2cdd44f4a8eed4b6faea8cf6
@@ -0,0 +1,91 @@
1
+ name: Tests
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ postgres:
7
+ name: Test against PostgreSQL
8
+ runs-on: ubuntu-latest
9
+ env:
10
+ DB_TYPE: postgres
11
+ DB_PASSWORD: password
12
+ DB_USERNAME: postgres
13
+ services:
14
+ postgres:
15
+ image: postgres
16
+ env:
17
+ POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
18
+ ports:
19
+ - 5432:5432
20
+ options: >-
21
+ --health-cmd pg_isready
22
+ --health-interval 10s
23
+ --health-timeout 5s
24
+ --health-retries 5
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: ruby/setup-ruby@v1
28
+ with:
29
+ bundler-cache: true
30
+ - run: bundle exec rake test:db:create
31
+ - run: bundle exec rspec spec
32
+ - uses: actions/upload-artifact@v3
33
+ with:
34
+ name: postgres-test-coverage
35
+ path: coverage/lcov/csv_fast_importer.lcov
36
+
37
+ mysql:
38
+ name: Test against MySQL
39
+ runs-on: ubuntu-latest
40
+ env:
41
+ DB_TYPE: mysql
42
+ DB_HOST: 127.0.0.1
43
+ DB_PORT: 3306
44
+ DB_ROOT_PASSWORD: password
45
+ DB_USERNAME: mysql
46
+ DB_PASSWORD: password
47
+ DB_DATABASE: csv_fast_importer_test
48
+ services:
49
+ mysql:
50
+ image: mysql
51
+ env:
52
+ MYSQL_DATABASE: ${{ env.DB_DATABASE }}
53
+ MYSQL_USER: ${{ env.DB_USERNAME }}
54
+ MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
55
+ MYSQL_ROOT_PASSWORD: ${{ env.DB_ROOT_PASSWORD }}
56
+ ports:
57
+ - 3306:3306
58
+ options: >-
59
+ --health-cmd="mysqladmin ping"
60
+ --health-interval=10s
61
+ --health-timeout=5s
62
+ --health-retries=3
63
+ steps:
64
+ - uses: actions/checkout@v4
65
+ - uses: ruby/setup-ruby@v1
66
+ with:
67
+ bundler-cache: true
68
+ - name: Enable local data loading
69
+ run: |
70
+ mysql --host=${{ env.DB_HOST }} --user=root --password=${{ env.DB_ROOT_PASSWORD }} ${{ env.DB_DATABASE }} <<MY_QUERY
71
+ set global local_infile=true;
72
+ MY_QUERY
73
+ - run: bundle exec rspec spec
74
+ - uses: actions/upload-artifact@v3
75
+ with:
76
+ name: mysql-test-coverage
77
+ path: coverage/lcov/csv_fast_importer.lcov
78
+
79
+ test-coverage:
80
+ name: Publish test coverage
81
+ needs: [postgres, mysql]
82
+ runs-on: ubuntu-latest
83
+ steps:
84
+ - name: Recover all test coverages
85
+ uses: actions/download-artifact@v3
86
+ - run: ls -R
87
+ - name: Upload coverage to Codacy
88
+ uses: codacy/codacy-coverage-reporter-action@v1
89
+ with:
90
+ project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
91
+ coverage-reports: postgres-test-coverage/csv_fast_importer.lcov, mysql-test-coverage/csv_fast_importer.lcov
data/.gitignore CHANGED
@@ -9,6 +9,7 @@
9
9
  /test/tmp/
10
10
  /test/version_tmp/
11
11
  /tmp/
12
+ /.idea/
12
13
 
13
14
  ## Specific to RubyMotion:
14
15
  .dat*
@@ -18,7 +19,6 @@ build/
18
19
  ## Documentation cache and generated files:
19
20
  /.yardoc/
20
21
  /_yardoc/
21
- /doc/
22
22
  /rdoc/
23
23
 
24
24
  ## Environment normalization:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.6.10
data/Gemfile.lock CHANGED
@@ -1,74 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv_fast_importer (1.0.0)
5
- activerecord (>= 3.0)
4
+ csv_fast_importer (1.2.0)
5
+ activerecord (~> 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  active_importer (0.2.6)
11
11
  roo
12
- activemodel (4.2.5)
13
- activesupport (= 4.2.5)
12
+ activemodel (4.2.11.3)
13
+ activesupport (= 4.2.11.3)
14
14
  builder (~> 3.1)
15
- activerecord (4.2.5)
16
- activemodel (= 4.2.5)
17
- activesupport (= 4.2.5)
15
+ activerecord (4.2.11.3)
16
+ activemodel (= 4.2.11.3)
17
+ activesupport (= 4.2.11.3)
18
18
  arel (~> 6.0)
19
19
  activerecord-import (0.10.0)
20
20
  activerecord (>= 3.0)
21
- activesupport (4.2.5)
21
+ activesupport (4.2.11.3)
22
22
  i18n (~> 0.7)
23
- json (~> 1.7, >= 1.7.7)
24
23
  minitest (~> 5.1)
25
24
  thread_safe (~> 0.3, >= 0.3.4)
26
25
  tzinfo (~> 1.1)
27
- arel (6.0.3)
26
+ arel (6.0.4)
28
27
  axiom-types (0.1.1)
29
28
  descendants_tracker (~> 0.0.4)
30
29
  ice_nine (~> 0.11.0)
31
30
  thread_safe (~> 0.3, >= 0.3.1)
32
- builder (3.2.2)
31
+ builder (3.2.4)
33
32
  bulk_insert (1.5.0)
34
33
  activerecord (>= 4.1.0)
35
- codacy-coverage (0.2.3)
36
- rest-client (~> 1.8)
37
- simplecov (~> 0.10.0)
38
34
  coercible (1.0.0)
39
35
  descendants_tracker (~> 0.0.1)
36
+ concurrent-ruby (1.2.2)
40
37
  csv-importer (0.3.2)
41
38
  virtus
42
39
  descendants_tracker (0.0.4)
43
40
  thread_safe (~> 0.3, >= 0.3.1)
44
41
  diff-lcs (1.2.5)
45
- docile (1.1.5)
46
- domain_name (0.5.20160216)
47
- unf (>= 0.0.5, < 1.0.0)
42
+ docile (1.4.0)
48
43
  equalizer (0.0.11)
49
44
  ferry (2.0.0)
50
45
  highline (~> 1.6.21)
51
46
  progressbar (~> 0.21.0)
52
47
  highline (1.6.21)
53
- http-cookie (1.0.2)
54
- domain_name (~> 0.5)
55
- i18n (0.7.0)
48
+ i18n (0.9.5)
49
+ concurrent-ruby (~> 1.0)
56
50
  ice_nine (0.11.2)
57
- json (1.8.3)
58
- mime-types (2.99.1)
59
- mini_portile2 (2.2.0)
60
- minitest (5.8.3)
61
- mysql2 (0.3.20)
62
- netrc (0.11.0)
63
- nokogiri (1.8.0)
64
- mini_portile2 (~> 2.2.0)
65
- pg (0.18.4)
51
+ mini_portile2 (2.3.0)
52
+ minitest (5.20.0)
53
+ mysql2 (0.4.10)
54
+ nokogiri (1.8.2)
55
+ mini_portile2 (~> 2.3.0)
56
+ pg (0.21.0)
66
57
  progressbar (0.21.0)
67
58
  rake (10.4.2)
68
- rest-client (1.8.0)
69
- http-cookie (>= 1.0.2, < 2.0)
70
- mime-types (>= 1.16, < 3.0)
71
- netrc (~> 0.7)
72
59
  roo (2.7.1)
73
60
  nokogiri (~> 1)
74
61
  rubyzip (~> 1.1, < 2.0.0)
@@ -85,19 +72,18 @@ GEM
85
72
  diff-lcs (>= 1.2.0, < 2.0)
86
73
  rspec-support (~> 3.4.0)
87
74
  rspec-support (3.4.1)
88
- rubyzip (1.2.1)
89
- simplecov (0.10.0)
90
- docile (~> 1.1.0)
91
- json (~> 1.8)
92
- simplecov-html (~> 0.10.0)
93
- simplecov-html (0.10.0)
75
+ rubyzip (1.3.0)
76
+ simplecov (0.22.0)
77
+ docile (~> 1.1)
78
+ simplecov-html (~> 0.11)
79
+ simplecov_json_formatter (~> 0.1)
80
+ simplecov-html (0.12.3)
81
+ simplecov-lcov (0.8.0)
82
+ simplecov_json_formatter (0.1.4)
94
83
  smarter_csv (1.1.4)
95
- thread_safe (0.3.5)
96
- tzinfo (1.2.2)
84
+ thread_safe (0.3.6)
85
+ tzinfo (1.2.11)
97
86
  thread_safe (~> 0.1)
98
- unf (0.1.4)
99
- unf_ext
100
- unf_ext (0.0.7.2)
101
87
  upsert (2.2.1)
102
88
  virtus (1.0.5)
103
89
  axiom-types (~> 0.1)
@@ -113,16 +99,17 @@ DEPENDENCIES
113
99
  activerecord-import
114
100
  bulk_insert
115
101
  bundler (~> 1.10)
116
- codacy-coverage
117
102
  csv-importer
118
103
  csv_fast_importer!
119
104
  ferry
120
- mysql2 (>= 0.3.10)
121
- pg (>= 0.18.4)
105
+ mysql2 (>= 0.4.0)
106
+ pg (~> 0.21.0)
122
107
  rake (~> 10.0)
123
108
  rspec
109
+ simplecov
110
+ simplecov-lcov
124
111
  smarter_csv
125
112
  upsert
126
113
 
127
114
  BUNDLED WITH
128
- 1.13.2
115
+ 1.17.3
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Build Status](https://travis-ci.org/sogilis/csv_fast_importer.svg?branch=master)](https://travis-ci.org/sogilis/csv_fast_importer) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3747d356ba004b7da2d0aec6bf1160f0)](https://www.codacy.com/app/Jibidus/csv_fast_importer?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=sogilis/csv_fast_importer&amp;utm_campaign=Badge_Grade)
1
+ [![Gem Version](https://badge.fury.io/rb/csv_fast_importer.svg)](https://badge.fury.io/rb/csv_fast_importer) ![Tests status](https://github.com/sogilis/csv_fast_importer/actions/workflows/tests.yml/badge.svg) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1ecd555b2ff3414d92bc8674b29c68ea)](https://www.codacy.com/gh/sogilis/csv_fast_importer/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=sogilis/csv_fast_importer&amp;utm_campaign=Badge_Grade)
2
+
2
3
 
3
4
  # CSV Fast Importer
4
5
 
@@ -23,17 +24,19 @@ Like all benchmarks, some tuning can produce different results, yet this chart g
23
24
 
24
25
  - Usual ActiveRecord process (validations, callbacks, computed fields like `created_at`...) is bypassed. This is the price for performance
25
26
  - Custom enclosing field (ex: `"`) is not supported yet
26
- - Custom line serparator (ex: `\r\n` for windows file) is not supported yet
27
+ - Custom line separator (ex: `\r\n` for windows file) is not supported yet
27
28
  - MySQL: encoding is not supported yet
28
29
  - MySQL: transaction is not supported yet
29
30
  - MySQL: row_index is not supported yet
30
31
 
32
+ Note about custom line separator: it might work by opening the file with the `universal_newline` argument (e.g. `file = File.new(path, universal_newline: true)`). Unfortunately, we weren't able to reproduce and test it so we don't support it "officialy". You can find more information in [this ticket](https://github.com/sogilis/csv_fast_importer/pull/45#issuecomment-326578839) (in French).
33
+
31
34
  ## Installation
32
35
 
33
36
  Add the dependency to your Gemfile:
34
37
 
35
- ```gemfile
36
- gem 'csv_fast_importer`
38
+ ```ruby
39
+ gem 'csv_fast_importer'
37
40
  ```
38
41
 
39
42
  Run `bundle install`.
@@ -71,7 +74,7 @@ For instance, a `FIRSTNAME` CSV column will be mapped to the `firstname` field.
71
74
 
72
75
  | Option key | Purpose | Default value |
73
76
  | ------------ | ------------- | ------------- |
74
- | *encoding* | File encoding. *PostgreSQL only*| `'UTF-8'` |
77
+ | *encoding* | File encoding. *PostgreSQL only* (see [FAQ](doc/faq.md) for more details)| `'UTF-8'` |
75
78
  | *col_sep* | Column separator in file | `';'` |
76
79
  | *destination* | Destination table | given base filename (without extension) |
77
80
  | *mapping* | Column mapping | `{}` |
@@ -79,11 +82,10 @@ For instance, a `FIRSTNAME` CSV column will be mapped to the `firstname` field.
79
82
  | *transaction* | Execute DELETE and INSERT in same transaction. *PostgreSQL only* | `:enabled` |
80
83
  | *deletion* | Row deletion method (`:delete` for SQL DELETE, `:truncate` for SQL TRUNCATE or `:none` for no deletion before import) | `:delete` |
81
84
 
82
- Your CSV file should be encoding in UTF-8 but you can specify another encoding
83
- with the `encoding` option (*PostgreSQL only*).
85
+ If your CSV file is not encoded with same table than your database, you can specify encoding at the file opening (see [FAQ](doc/faq.md) for more details):
84
86
 
85
87
  ```ruby
86
- CsvFastImporter.import file, encoding: 'ISO-8859-1'
88
+ file = File.new '/path/to/knights.csv', encoding: 'ISO-8859-1'
87
89
  ```
88
90
 
89
91
  You can specify a different separator column with the `col_sep` option (`;` by
@@ -117,15 +119,21 @@ Lancelot;lancelot@logre.cel
117
119
  To map the `KNIGHT_EMAIL` column to the `email` database field:
118
120
 
119
121
  ```ruby
120
- CsvFastImporter.import file, mapping: { email: :knight_email }
122
+ CsvFastImporter.import file, mapping: { knight_email: :email }
121
123
  ```
122
124
 
125
+ ## Need help?
126
+
127
+ See [FAQ](doc/faq.md).
128
+
123
129
  ## How to contribute?
124
130
 
125
131
  You can fork and submit new pull request (with tests and explanations).
126
132
  First of all, you need to initialize your environment :
127
133
 
128
134
  ```sh
135
+ $ brew install postgresql # in macOS
136
+ $ apt-get install libpq-dev # in Linux
129
137
  $ bundle install
130
138
  ```
131
139
 
@@ -136,6 +144,8 @@ $ bundle exec rake test:db:create
136
144
  ```
137
145
  This will connect to `localhost` PostgreSQL database without user (see `config/database.postgres.yml`) and create a new database dedicated to tests.
138
146
 
147
+ *Warning:* database instance have to allow database creation with `UTF-8` encoding.
148
+
139
149
  Finally, you can run all tests with RSpec like this:
140
150
 
141
151
  ```sh
@@ -156,9 +166,6 @@ Use `DB_TYPE=mysql DB_USERNAME=` (with empty username) for anonymous account.
156
166
 
157
167
  `master` is the development branch and releases are published as tags.
158
168
 
159
- **We're not ready for the production yet (version < 1.0) so use this gem with
160
- precaution.**
161
-
162
169
  We follow the [Semantic Versioning 2.0.0](http://semver.org/) for our gem
163
170
  releases.
164
171
 
@@ -184,3 +191,21 @@ In few words:
184
191
  - [ ] Refactor tests (with should-> must / should -> expect / subject...)
185
192
  - [ ] Reduce technical debt on db connection (test & benchmark)
186
193
  - [ ] SQLite support
194
+
195
+ ## How to release new version?
196
+
197
+ Setup rubygems.org account:
198
+
199
+ ```bash
200
+ curl -u {your_gem_account_name} https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
201
+ chmod 0600 ~/.gem/credentials
202
+ ```
203
+
204
+ Make sure you are in `master` branch and run:
205
+
206
+ ```bash
207
+ bundle exec rake "release:make[major|minor|patch|x.y.z]"
208
+ ```
209
+ Example: `bundle exec rake "release:make[minor]"`
210
+
211
+ Then, follow instructions.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ namespace :test do
13
13
  when :postgres
14
14
  require 'pg'
15
15
  db.connect 'postgres'
16
- ActiveRecord::Base.connection.execute "CREATE DATABASE #{db.name}"
16
+ ActiveRecord::Base.connection.execute "CREATE DATABASE #{db.name} ENCODING='UTF-8'"
17
17
 
18
18
  when :mysql
19
19
  require 'mysql2'
data/benchmark/README.md CHANGED
@@ -133,7 +133,7 @@ bundle exec rake test:db:create
133
133
  ```
134
134
 
135
135
  Execute benchmark
136
- ```
136
+ ```shell
137
137
  bundle exec rake benchmark
138
138
  ```
139
139
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["sogilis@sogilis.com"]
11
11
 
12
12
  spec.summary = "Fast CSV Importer"
13
- spec.description = "Import CSV files' content into a PostgreSQL database. It is based on the Postgre COPY command which is designed to be as faster as possible."
13
+ spec.description = "A gem to import CSV files' content into a PostgreSQL or MySQL database. It is respectively based on PostgreSQL COPY and MySQL LOAD DATA INFILE which are designed to be as fast as possible."
14
14
  spec.homepage = "https://github.com/sogilis/csv_fast_importer"
15
15
  spec.license = "MIT"
16
16
 
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.10"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "pg", ">= 0.18.4"
28
- spec.add_development_dependency "mysql2", ">= 0.3.10"
29
- spec.add_development_dependency "codacy-coverage"
27
+ spec.add_development_dependency "pg", "~> 0.21.0"
28
+ spec.add_development_dependency "mysql2", ">= 0.4.0"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "simplecov-lcov"
30
31
  spec.add_development_dependency "rspec"
31
32
 
32
33
  # Only for benchmark
@@ -38,5 +39,5 @@ Gem::Specification.new do |spec|
38
39
  spec.add_development_dependency "active_importer"
39
40
  spec.add_development_dependency "ferry"
40
41
 
41
- spec.add_runtime_dependency "activerecord", [">= 3.0"]
42
+ spec.add_runtime_dependency "activerecord", ["~> 4.2"]
42
43
  end
data/doc/faq.md ADDED
@@ -0,0 +1,64 @@
1
+ # Frequently Asked Questions
2
+
3
+ ## How to specify encoding?
4
+
5
+ Multiple components are involved when `CSV Fast Importer` is executed:
6
+
7
+ - file
8
+ - ruby `File` wrapper
9
+ - database client (managed by `ActiveRecord` connection)
10
+ - SQL command (`COPY` for PostgreSQL)
11
+ - database server
12
+
13
+ Encoding must be consistent accross all these components. Here is how to specify or check each component encoding.
14
+
15
+ ### File
16
+
17
+ You can get current file encoding with `file -i [file_path]` (`-I` on macOS) command.
18
+ Some tools like [iconv](http://www.gnu.org/savannah-checkouts/gnu/libiconv/documentation/libiconv-1.15/iconv.1.html) can modify file encoding.
19
+
20
+ ### Ruby `File` wrapper
21
+
22
+ `File` uses default Ruby encoding (given by `Encoding.default_external`. See [External / Internal Encoding](https://ruby-doc.org/core-2.4.1/Encoding.html#class-Encoding-label-External+encoding) which might be different from file enoding!
23
+
24
+ ```ruby
25
+ File.new 'path/to/file.csv'
26
+ ```
27
+
28
+ But, you can specify encoding with `encoding` parameter:
29
+
30
+ ```ruby
31
+ File.new 'path/to/file.csv', encoding: 'ISO-8859-1'
32
+ ```
33
+
34
+ Ruby `File` can also handle internal and external encoding (see [File::new](https://ruby-doc.org/core-2.4.1/File.html#method-c-new) which can be useful to manage automatic conversion:
35
+
36
+ ```ruby
37
+ File.new 'path/to/file.csv', external_encoding: 'ISO-8859-1', internal_encoding: 'UTF-8'
38
+ # or
39
+ File.new 'path/to/file.csv', encoding: 'ISO-8859-1:UTF-8'
40
+ ```
41
+
42
+ ### Database client
43
+
44
+ Database is accessed through a dedicated client.
45
+ This client is managed by `ActiveRecord` with some configuration (`database.yml` in Rails application) where `encoding` parameter can be defined.
46
+
47
+ ### SQL Command
48
+
49
+ By default, `COPY` and `LOAD DATA INFILE` commands follow database client encoding configuration. But you can override this with dedicated parameter.
50
+ This is the purpose of `CSV FAST Importer`'s `encoding` parameter.
51
+
52
+ ### Database server
53
+
54
+ Each Postgres server instance is encoded with a specific table. You can show this with following command:
55
+
56
+ ```shell
57
+ psql -l
58
+ ```
59
+
60
+ Or, from `psql` client:
61
+
62
+ ```sql
63
+ \l
64
+ ```
@@ -1,3 +1,3 @@
1
1
  module CSVFastImporter
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,28 @@
1
+ class Changelog
2
+ attr_reader :changelog
3
+
4
+ def initialize(changelog)
5
+ @changelog = changelog
6
+ end
7
+
8
+ def self.parse(git_log)
9
+ changelog = {}
10
+ git_log.sort.uniq.each do |commit_message|
11
+ type, message = commit_message.split('/', 2).map(&:strip)
12
+ next if type == 'Chore'
13
+ if message.nil?
14
+ message = type
15
+ type = 'Other'
16
+ end
17
+ changelog[type] = [] unless changelog.has_key?(type)
18
+ changelog[type] << message
19
+ end
20
+ Changelog.new changelog
21
+ end
22
+
23
+ def to_s
24
+ @changelog.map do |type, messages|
25
+ "# #{type}\n" + messages.map { |message| "- #{message}\n" }.join + "\n"
26
+ end.join
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require './rakelib/repository'
2
+ require './rakelib/release'
3
+
4
+ namespace :release do
5
+
6
+ desc "Build new release.\n\t- bump_type (mandatory): [major|minor|patch|x.y.z]\n\t- dry_run (optional): skip commit, tag and publishing"
7
+ task :make, [:bump_type, :dry_run] do |_, args|
8
+ release = Release.new args[:bump_type]
9
+ #raise "You can only release new version from master branch" unless Repository.current_branch == 'master'
10
+
11
+ puts "Bump version from #{release.last_version} to #{release.version}"
12
+ release.apply!
13
+
14
+ puts
15
+ puts "Changelog from #{release.last_version} to #{release.version}"
16
+ puts "---------------------------------------------------------------------"
17
+ puts release.changelog
18
+ puts "(Chores ignored)"
19
+ puts "---------------------------------------------------------------------"
20
+
21
+ next if args[:dry_run]
22
+
23
+ release.git_commit
24
+
25
+ puts
26
+ puts "Release built."
27
+ puts
28
+ puts "Run following commands to publish version #{release.version}:"
29
+ puts "$ git push && git push --tags"
30
+ puts "$ bundle exec rake release"
31
+ puts
32
+ puts "After that, do not forget to report changelog in Github Releases page:"
33
+ puts "https://github.com/sogilis/csv_fast_importer/releases"
34
+ end
35
+ end
36
+
@@ -0,0 +1,60 @@
1
+ require './rakelib/repository'
2
+ require './rakelib/changelog'
3
+
4
+ class Release
5
+
6
+ GEM_NAME = 'csv_fast_importer'
7
+ VERSION_FILE = 'lib/csv_fast_importer/version.rb'
8
+ GEMFILE_LOCK = 'Gemfile.lock'
9
+
10
+ def initialize(type)
11
+ @type = type
12
+ end
13
+
14
+ def last_version
15
+ CSVFastImporter::VERSION
16
+ end
17
+
18
+ def version
19
+ @version ||= bump(last_version, @type)
20
+ end
21
+
22
+ def apply!
23
+ sub_file_content VERSION_FILE, last_version, version
24
+ sub_file_content GEMFILE_LOCK, "#{GEM_NAME} (#{last_version})", "#{GEM_NAME} (#{version})"
25
+ end
26
+
27
+ def changelog
28
+ @changelog ||= Changelog.parse(Repository.log_from("v#{last_version}"))
29
+ end
30
+
31
+ def git_commit
32
+ `git add #{VERSION_FILE} #{GEMFILE_LOCK}`
33
+ `git commit -m 'Chore / Change version to #{version}'`
34
+ end
35
+
36
+ private
37
+
38
+ def bump(version, bump_type)
39
+ major, minor, patch = version.split(".").map(&:to_i)
40
+ if bump_type == 'major'
41
+ major += 1
42
+ minor = 0
43
+ patch = 0
44
+ elsif bump_type == 'minor'
45
+ minor += 1
46
+ patch = 0
47
+ else
48
+ patch += 1
49
+ end
50
+ [major, minor, patch].join(".")
51
+ end
52
+
53
+ def sub_file_content(file_path, from, to)
54
+ current_content = File.read(file_path)
55
+ modified_content = current_content.sub(from, to)
56
+ raise "Cannot find regexp #{from} in file #{file_path}" if modified_content == current_content
57
+ File.open(file_path, "w") { |file| file << modified_content }
58
+ end
59
+
60
+ end
@@ -0,0 +1,10 @@
1
+ class Repository
2
+
3
+ def self.current_branch
4
+ `git rev-parse --abbrev-ref HEAD`
5
+ end
6
+
7
+ def self.log_from(revision)
8
+ `git log #{revision}..HEAD --pretty=format:"%s"`.split("\n")
9
+ end
10
+ end
data/sample-app/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
 
4
4
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
- gem 'rails', '4.2.6'
5
+ gem 'rails', '~> 4.2'
6
6
  # Use sqlite3 as the database for Active Record
7
7
  #gem 'sqlite3'
8
8
  gem 'pg'
@@ -1,38 +1,37 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- actionmailer (4.2.6)
5
- actionpack (= 4.2.6)
6
- actionview (= 4.2.6)
7
- activejob (= 4.2.6)
4
+ actionmailer (4.2.11)
5
+ actionpack (= 4.2.11)
6
+ actionview (= 4.2.11)
7
+ activejob (= 4.2.11)
8
8
  mail (~> 2.5, >= 2.5.4)
9
9
  rails-dom-testing (~> 1.0, >= 1.0.5)
10
- actionpack (4.2.6)
11
- actionview (= 4.2.6)
12
- activesupport (= 4.2.6)
10
+ actionpack (4.2.11)
11
+ actionview (= 4.2.11)
12
+ activesupport (= 4.2.11)
13
13
  rack (~> 1.6)
14
14
  rack-test (~> 0.6.2)
15
15
  rails-dom-testing (~> 1.0, >= 1.0.5)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
- actionview (4.2.6)
18
- activesupport (= 4.2.6)
17
+ actionview (4.2.11)
18
+ activesupport (= 4.2.11)
19
19
  builder (~> 3.1)
20
20
  erubis (~> 2.7.0)
21
21
  rails-dom-testing (~> 1.0, >= 1.0.5)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
- activejob (4.2.6)
24
- activesupport (= 4.2.6)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
+ activejob (4.2.11)
24
+ activesupport (= 4.2.11)
25
25
  globalid (>= 0.3.0)
26
- activemodel (4.2.6)
27
- activesupport (= 4.2.6)
26
+ activemodel (4.2.11)
27
+ activesupport (= 4.2.11)
28
28
  builder (~> 3.1)
29
- activerecord (4.2.6)
30
- activemodel (= 4.2.6)
31
- activesupport (= 4.2.6)
29
+ activerecord (4.2.11)
30
+ activemodel (= 4.2.11)
31
+ activesupport (= 4.2.11)
32
32
  arel (~> 6.0)
33
- activesupport (4.2.6)
33
+ activesupport (4.2.11)
34
34
  i18n (~> 0.7)
35
- json (~> 1.7, >= 1.7.7)
36
35
  minitest (~> 5.1)
37
36
  thread_safe (~> 0.3, >= 0.3.4)
38
37
  tzinfo (~> 1.1)
@@ -48,16 +47,18 @@ GEM
48
47
  coffee-script-source
49
48
  execjs
50
49
  coffee-script-source (1.12.2)
51
- concurrent-ruby (1.0.5)
50
+ concurrent-ruby (1.1.4)
51
+ crass (1.0.4)
52
52
  csv_fast_importer (1.0.0)
53
53
  activerecord (>= 3.0)
54
54
  debug_inspector (0.0.3)
55
55
  erubis (2.7.0)
56
56
  execjs (2.7.0)
57
- ffi (1.9.18)
58
- globalid (0.4.0)
57
+ ffi (1.16.1)
58
+ globalid (0.4.1)
59
59
  activesupport (>= 4.2.0)
60
- i18n (0.8.6)
60
+ i18n (0.9.5)
61
+ concurrent-ruby (~> 1.0)
61
62
  jbuilder (2.7.0)
62
63
  activesupport (>= 4.2.0)
63
64
  multi_json (>= 1.2)
@@ -66,47 +67,46 @@ GEM
66
67
  railties (>= 4.2.0)
67
68
  thor (>= 0.14, < 2.0)
68
69
  json (1.8.6)
69
- loofah (2.0.3)
70
+ loofah (2.2.3)
71
+ crass (~> 1.0.2)
70
72
  nokogiri (>= 1.5.9)
71
- mail (2.6.6)
72
- mime-types (>= 1.16, < 4)
73
- mime-types (3.1)
74
- mime-types-data (~> 3.2015)
75
- mime-types-data (3.2016.0521)
76
- mini_portile2 (2.2.0)
77
- minitest (5.10.3)
73
+ mail (2.7.1)
74
+ mini_mime (>= 0.1.1)
75
+ mini_mime (1.0.1)
76
+ mini_portile2 (2.4.0)
77
+ minitest (5.11.3)
78
78
  multi_json (1.12.1)
79
- nokogiri (1.8.0)
80
- mini_portile2 (~> 2.2.0)
79
+ nokogiri (1.9.1)
80
+ mini_portile2 (~> 2.4.0)
81
81
  pg (0.19.0)
82
- rack (1.6.8)
82
+ rack (1.6.11)
83
83
  rack-test (0.6.3)
84
84
  rack (>= 1.0)
85
- rails (4.2.6)
86
- actionmailer (= 4.2.6)
87
- actionpack (= 4.2.6)
88
- actionview (= 4.2.6)
89
- activejob (= 4.2.6)
90
- activemodel (= 4.2.6)
91
- activerecord (= 4.2.6)
92
- activesupport (= 4.2.6)
85
+ rails (4.2.11)
86
+ actionmailer (= 4.2.11)
87
+ actionpack (= 4.2.11)
88
+ actionview (= 4.2.11)
89
+ activejob (= 4.2.11)
90
+ activemodel (= 4.2.11)
91
+ activerecord (= 4.2.11)
92
+ activesupport (= 4.2.11)
93
93
  bundler (>= 1.3.0, < 2.0)
94
- railties (= 4.2.6)
94
+ railties (= 4.2.11)
95
95
  sprockets-rails
96
96
  rails-deprecated_sanitizer (1.0.3)
97
97
  activesupport (>= 4.2.0.alpha)
98
- rails-dom-testing (1.0.8)
99
- activesupport (>= 4.2.0.beta, < 5.0)
98
+ rails-dom-testing (1.0.9)
99
+ activesupport (>= 4.2.0, < 5.0)
100
100
  nokogiri (~> 1.6)
101
101
  rails-deprecated_sanitizer (>= 1.0.1)
102
- rails-html-sanitizer (1.0.3)
103
- loofah (~> 2.0)
104
- railties (4.2.6)
105
- actionpack (= 4.2.6)
106
- activesupport (= 4.2.6)
102
+ rails-html-sanitizer (1.0.4)
103
+ loofah (~> 2.2, >= 2.2.2)
104
+ railties (4.2.11)
105
+ actionpack (= 4.2.11)
106
+ activesupport (= 4.2.11)
107
107
  rake (>= 0.8.7)
108
108
  thor (>= 0.18.1, < 2.0)
109
- rake (12.0.0)
109
+ rake (12.3.2)
110
110
  rb-fsevent (0.10.2)
111
111
  rb-inotify (0.9.10)
112
112
  ffi (>= 0.5.0, < 2)
@@ -127,20 +127,20 @@ GEM
127
127
  rdoc (~> 4.0)
128
128
  spring (2.0.2)
129
129
  activesupport (>= 4.2)
130
- sprockets (3.7.1)
130
+ sprockets (3.7.2)
131
131
  concurrent-ruby (~> 1.0)
132
132
  rack (> 1, < 3)
133
- sprockets-rails (3.2.0)
133
+ sprockets-rails (3.2.1)
134
134
  actionpack (>= 4.0)
135
135
  activesupport (>= 4.0)
136
136
  sprockets (>= 3.0.0)
137
- thor (0.20.0)
137
+ thor (0.20.3)
138
138
  thread_safe (0.3.6)
139
139
  tilt (2.0.8)
140
140
  turbolinks (5.0.1)
141
141
  turbolinks-source (~> 5)
142
142
  turbolinks-source (5.0.3)
143
- tzinfo (1.2.3)
143
+ tzinfo (1.2.5)
144
144
  thread_safe (~> 0.1)
145
145
  uglifier (3.2.0)
146
146
  execjs (>= 0.3.0, < 3)
@@ -160,7 +160,7 @@ DEPENDENCIES
160
160
  jbuilder (~> 2.0)
161
161
  jquery-rails
162
162
  pg
163
- rails (= 4.2.6)
163
+ rails (~> 4.2)
164
164
  sass-rails (~> 5.0)
165
165
  sdoc (~> 0.4.0)
166
166
  spring
@@ -169,4 +169,4 @@ DEPENDENCIES
169
169
  web-console (~> 2.0)
170
170
 
171
171
  BUNDLED WITH
172
- 1.13.2
172
+ 1.17.2
data/sample-app/README.md CHANGED
@@ -13,7 +13,7 @@ bundle exec rake db:setup
13
13
  - Execute `csv_fast_importer` rake task:
14
14
 
15
15
  ```bash
16
- bundle exec rake csv_fast_importe
16
+ bundle exec rake csv_fast_importer
17
17
  ```
18
18
 
19
19
  - Verify following output:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_fast_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sogilis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -40,34 +40,48 @@ dependencies:
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.21.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.21.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: 0.18.4
61
+ version: 0.4.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: 0.18.4
68
+ version: 0.4.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: mysql2
70
+ name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 0.3.10
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 0.3.10
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: codacy-coverage
84
+ name: simplecov-lcov
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -196,27 +210,28 @@ dependencies:
196
210
  name: activerecord
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
- - - ">="
213
+ - - "~>"
200
214
  - !ruby/object:Gem::Version
201
- version: '3.0'
215
+ version: '4.2'
202
216
  type: :runtime
203
217
  prerelease: false
204
218
  version_requirements: !ruby/object:Gem::Requirement
205
219
  requirements:
206
- - - ">="
220
+ - - "~>"
207
221
  - !ruby/object:Gem::Version
208
- version: '3.0'
209
- description: Import CSV files' content into a PostgreSQL database. It is based on
210
- the Postgre COPY command which is designed to be as faster as possible.
222
+ version: '4.2'
223
+ description: A gem to import CSV files' content into a PostgreSQL or MySQL database.
224
+ It is respectively based on PostgreSQL COPY and MySQL LOAD DATA INFILE which are
225
+ designed to be as fast as possible.
211
226
  email:
212
227
  - sogilis@sogilis.com
213
228
  executables: []
214
229
  extensions: []
215
230
  extra_rdoc_files: []
216
231
  files:
232
+ - ".github/workflows/tests.yml"
217
233
  - ".gitignore"
218
234
  - ".ruby-version"
219
- - ".travis.yml"
220
235
  - CONTRIBUTING.md
221
236
  - Gemfile
222
237
  - Gemfile.lock
@@ -231,6 +246,7 @@ files:
231
246
  - benchmark/strategies.rb
232
247
  - benchmark/tools.rb
233
248
  - csv_fast_importer.gemspec
249
+ - doc/faq.md
234
250
  - lib/csv_fast_importer.rb
235
251
  - lib/csv_fast_importer/configuration.rb
236
252
  - lib/csv_fast_importer/database/mysql.rb
@@ -240,6 +256,10 @@ files:
240
256
  - lib/csv_fast_importer/database_factory.rb
241
257
  - lib/csv_fast_importer/import.rb
242
258
  - lib/csv_fast_importer/version.rb
259
+ - rakelib/changelog.rb
260
+ - rakelib/release.rake
261
+ - rakelib/release.rb
262
+ - rakelib/repository.rb
243
263
  - sample-app/.gitignore
244
264
  - sample-app/Gemfile
245
265
  - sample-app/Gemfile.lock
@@ -307,7 +327,7 @@ homepage: https://github.com/sogilis/csv_fast_importer
307
327
  licenses:
308
328
  - MIT
309
329
  metadata: {}
310
- post_install_message:
330
+ post_install_message:
311
331
  rdoc_options: []
312
332
  require_paths:
313
333
  - lib
@@ -322,10 +342,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
342
  - !ruby/object:Gem::Version
323
343
  version: '0'
324
344
  requirements: []
325
- rubyforge_project:
326
- rubygems_version: 2.6.4
327
- signing_key:
345
+ rubygems_version: 3.0.3.1
346
+ signing_key:
328
347
  specification_version: 4
329
348
  summary: Fast CSV Importer
330
349
  test_files: []
331
- has_rdoc:
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: ruby
2
- script:
3
- - bundle exec rake test:db:create
4
- - bundle exec rspec spec
5
- - if [ "$RUN_BENCHMARK" = "true" ]; then DATASET_SIZE=100 bundle exec rake benchmark; fi
6
- rvm:
7
- 2.2.0
8
- matrix:
9
- include:
10
- - env:
11
- - DB_TYPE=mysql
12
- - DB_USERNAME=travis
13
- - env:
14
- - DB_TYPE=postgres
15
- - RUN_BENCHMARK=true