seed-snapshot 0.7.0 → 0.8.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 +4 -4
- data/.github/workflows/main.yml +2 -5
- data/.github/workflows/release.yml +43 -0
- data/AGENTS.md +55 -0
- data/compose.yaml +19 -0
- data/gemfiles/{ar_7.0.gemfile → ar_8.1.gemfile} +1 -1
- data/lib/seed/configuration.rb +2 -12
- data/lib/seed_snapshot/version.rb +1 -1
- data/seed-snapshot.gemspec +1 -1
- metadata +8 -7
- data/gemfiles/ar_7.1.gemfile +0 -9
- data/lib/seed/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8c4741381c5ac0fa4c2faedf03223b60d7a1b6eb484d6523c0a162ee96edf54
|
|
4
|
+
data.tar.gz: 5166c21119588ee4ad4d9a625aeaca78d9e7f6aea4be5dff087cec5b0f5a40f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e28c974fcc4b4ed0746c6bd8a3493486843af014274c1cd58340e57a9a45ddd1a6af4ba0cec1d954acd18adab085d9deb336895216c7e5a268876ece57b7de8
|
|
7
|
+
data.tar.gz: a2bb46155b7346cc90635aaee2c1e93e65580d92b159c1356c12666cd018148284f1830840b6920b6747dcf0196179f2ec4ae1583623b95ffefaeaaf923b0c0f
|
data/.github/workflows/main.yml
CHANGED
|
@@ -31,11 +31,8 @@ jobs:
|
|
|
31
31
|
strategy:
|
|
32
32
|
fail-fast: false
|
|
33
33
|
matrix:
|
|
34
|
-
ruby: ['3.
|
|
35
|
-
ar: ['7.
|
|
36
|
-
exclude:
|
|
37
|
-
- ruby: '3.1'
|
|
38
|
-
ar: '8.0'
|
|
34
|
+
ruby: ['3.3', '3.4', '4.0']
|
|
35
|
+
ar: ['7.2', '8.0', '8.1']
|
|
39
36
|
|
|
40
37
|
env:
|
|
41
38
|
BUNDLE_GEMFILE: gemfiles/ar_${{ matrix.ar }}.gemfile
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# v0.8.0 のようなタグを push すると rubygems.org に gem を公開する
|
|
4
|
+
# 認証は RubyGems の Trusted Publishing(OIDC)を使うので API キーは不要
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
tags:
|
|
8
|
+
- 'v*'
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
release:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: write
|
|
19
|
+
id-token: write
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
with:
|
|
25
|
+
persist-credentials: false
|
|
26
|
+
|
|
27
|
+
- name: Set up Ruby
|
|
28
|
+
uses: ruby/setup-ruby@v1
|
|
29
|
+
with:
|
|
30
|
+
ruby-version: ruby
|
|
31
|
+
bundler-cache: true
|
|
32
|
+
|
|
33
|
+
# タグと lib/seed_snapshot/version.rb のバージョンが一致しなければ中断する
|
|
34
|
+
- name: Check version
|
|
35
|
+
run: |
|
|
36
|
+
version=$(ruby -Ilib -e 'require "seed_snapshot/version"; print SeedSnapshot::VERSION')
|
|
37
|
+
if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then
|
|
38
|
+
echo "::error::Tag ${GITHUB_REF_NAME} does not match SeedSnapshot::VERSION (${version})"
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
- name: Release gem
|
|
43
|
+
uses: rubygems/release-gem@v1
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to AI coding agents (Claude Code, Codex, etc.) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
`seed-snapshot` は ActiveRecord (>= 7.2) 向けの gem で、テスト用のシードデータを `mysqldump` / `mysql` CLI で高速にダンプ・リストアする。**MySQL (Mysql2 アダプタ) 専用**で、`Seed::Configuration` の初期化時に他アダプタだと例外を投げる。
|
|
8
|
+
|
|
9
|
+
## コマンド
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
bin/setup # bundle install
|
|
13
|
+
bundle exec rake # 全テスト実行(default タスク = test)
|
|
14
|
+
bundle exec ruby -Ilib -Itest test/cases/dump_test.rb # 単一ファイル
|
|
15
|
+
bundle exec ruby -Ilib -Itest test/cases/dump_test.rb -n test_dump # 単一テスト
|
|
16
|
+
BUNDLE_GEMFILE=gemfiles/ar_8.0.gemfile bundle exec rake # 特定の ActiveRecord バージョンで実行
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**リリース**: `lib/seed_snapshot/version.rb` のバージョンを上げて master にマージした後、`git tag v<バージョン> && git push origin v<バージョン>` でタグを push すると、`.github/workflows/release.yml` が rubygems.org に公開する(RubyGems の Trusted Publishing を使用)。タグとバージョンが一致しないと失敗する。
|
|
20
|
+
|
|
21
|
+
## テスト環境
|
|
22
|
+
|
|
23
|
+
テストには実際の MySQL が必要(既定は `127.0.0.1:3306`、`root` / パスワード空)。
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
docker compose up -d --wait # CI と同じ MySQL 8.0 を起動(compose.yaml)
|
|
27
|
+
bundle exec rake
|
|
28
|
+
docker compose down # データは tmpfs なので停止すると消える
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- **接続先の上書き**: `test/config.yml` は `DB_HOST` / `DB_PORT` / `DB_USERNAME` / `DB_PASSWORD` を参照する。`ARCONFIG` で `test/config.yml` 自体を差し替え可能。3306 が埋まっている場合は `DB_PORT=13306 docker compose up -d --wait` で起動し、テストも同じ `DB_PORT` で実行する。
|
|
32
|
+
- **起動待ち**: コンテナは起動のたびに初期化が走り、接続可能になるまで数秒かかる。`test/cases/db_config.rb` の `wait_for_connection` が接続エラーの間だけ最大 30 秒リトライするので、`--wait` なしの `docker compose up -d` 直後に実行しても動く。
|
|
33
|
+
- **MySQL クライアント**: gem 本体がホスト上で `mysqldump` / `mysql` を実行する。PATH 上に `mysqldump` が無い場合は `test/support/mysql_client.rb` が `test/bin` を PATH に足し、compose の mysql コンテナ内のクライアントを `docker compose exec` 経由で使う(`test/bin/mysqldump` は `test/bin/mysql` へのシンボリックリンク。`-h` / `-P` はコンテナ内の `127.0.0.1:3306` に上書きする)。CI ではランナー(`ubuntu-latest`)にプリインストールされたクライアントが使われる。
|
|
34
|
+
- **DB・テーブルの作成**: 各テストが `require 'cases/helper'` → `test/cases/db_config.rb` の順に読み込み、テスト起動時に以下を行う。
|
|
35
|
+
1. `create_database_if_not_exists` が `activerecord_unittest` / `activerecord_unittest2` を作成(DB 名は `test/support/config.rb` の `expand_config` が接続名 `arunit` / `arunit2` に割り当てる。既存なら何もしない)
|
|
36
|
+
2. `ARTest.connect` で `arunit`(`activerecord_unittest`)に接続
|
|
37
|
+
3. `load_schema` が `test/schema/schema.rb` をロードし、`rents` / `books` / `users` を `force: true` で毎回作り直す
|
|
38
|
+
|
|
39
|
+
`activerecord_unittest2` は DB を作るだけで、テーブルは作られず現状のテストでも使われていない。
|
|
40
|
+
|
|
41
|
+
CI(`.github/workflows/main.yml`)は Ruby 3.3〜4.0 × ActiveRecord 7.2〜8.1 のマトリクスを `gemfiles/ar_*.gemfile` で回す(MySQL 8.0)。サポートが終了した Ruby / Rails は基本的に外す方針(ただし Rails 7.2 は EOL 後も残している)。サポートする AR バージョンを増減する場合は gemfile・CI マトリクス・gemspec の `activerecord` 依存をまとめて更新する。
|
|
42
|
+
|
|
43
|
+
## アーキテクチャ
|
|
44
|
+
|
|
45
|
+
- `lib/seed-snapshot.rb` — 公開 API(`SeedSnapshot.dump(classes:, ignore_classes:, force:)`, `.restore`, `.exists?`, `.clean`, `.manifest`)。呼び出しごとに `Seed::Configuration` を新規生成する。
|
|
46
|
+
- `Seed::Configuration` — 接続情報・パスを解決する。ダンプファイルは `Dir.pwd/tmp/dump/<schema_version>.sql`。`schema_version` は**マイグレーションバージョン一覧の SHA1** なので、マイグレーションが変わるとスナップショットは自動的に無効化(別ファイル扱い)される。`get_all_versions` は `MigrationContext#get_all_versions` を使う。
|
|
47
|
+
- `Seed::Snapshot` — dump/restore/clean の本体。モデルクラスから `table_name` を取り出して `Seed::Mysql` に渡す。`ar_internal_metadata` と `schema_migrations` は常に除外(`--ignore-table` は `db.table` 形式が必要)。
|
|
48
|
+
- `Seed::Mysql` — `system` でシェルコマンドを組み立てて実行。`mysqldump -t`(データのみ、スキーマなし)。クライアントバージョンが 8 系なら `--skip-column-statistics` を付ける。
|
|
49
|
+
- `Seed::Manifest` — シードファイル群の SHA256 を `tmp/dump/seed_manifest.json` に保存し、`diff?` でシード入力の変更を検知するための補助。
|
|
50
|
+
|
|
51
|
+
## 注意点
|
|
52
|
+
|
|
53
|
+
- バージョン定義は `lib/seed_snapshot/version.rb`(gemspec が参照)。
|
|
54
|
+
- README の Usage 例(`SeedSnapshot.restore(tables)` / `dump(tables)`)は現在のキーワード引数 API と一致していない。
|
|
55
|
+
- テストは `Dir.pwd` 基準で `tmp/dump` を作るため、リポジトリルートから実行すること。
|
data/compose.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 開発/テスト用 MySQL(CI の services と同じ構成)
|
|
2
|
+
# docker compose up -d --wait
|
|
3
|
+
# bundle exec rake
|
|
4
|
+
services:
|
|
5
|
+
mysql:
|
|
6
|
+
image: mysql:8.0
|
|
7
|
+
environment:
|
|
8
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
|
9
|
+
MYSQL_DATABASE: activerecord_unittest
|
|
10
|
+
ports:
|
|
11
|
+
- "${DB_PORT:-3306}:3306"
|
|
12
|
+
# テスト用なのでデータは永続化せずメモリ上に置く
|
|
13
|
+
tmpfs:
|
|
14
|
+
- /var/lib/mysql
|
|
15
|
+
healthcheck:
|
|
16
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
|
|
17
|
+
interval: 5s
|
|
18
|
+
timeout: 5s
|
|
19
|
+
retries: 20
|
data/lib/seed/configuration.rb
CHANGED
|
@@ -41,18 +41,8 @@ module Seed
|
|
|
41
41
|
private
|
|
42
42
|
|
|
43
43
|
def get_all_versions
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
::ActiveRecord::MigrationContext.new(migration_paths).get_all_versions
|
|
47
|
-
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new('6.0')
|
|
48
|
-
migration_paths = ::ActiveRecord::Migrator.migrations_paths
|
|
49
|
-
::ActiveRecord::MigrationContext.new(migration_paths, ::ActiveRecord::SchemaMigration).get_all_versions
|
|
50
|
-
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new('5.2')
|
|
51
|
-
migration_paths = ::ActiveRecord::Migrator.migrations_paths
|
|
52
|
-
::ActiveRecord::MigrationContext.new(migration_paths).get_all_versions
|
|
53
|
-
else
|
|
54
|
-
::ActiveRecord::Migrator.get_all_versions
|
|
55
|
-
end
|
|
44
|
+
migration_paths = ::ActiveRecord::Migrator.migrations_paths
|
|
45
|
+
::ActiveRecord::MigrationContext.new(migration_paths).get_all_versions
|
|
56
46
|
end
|
|
57
47
|
end
|
|
58
48
|
end
|
data/seed-snapshot.gemspec
CHANGED
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.require_paths = ['lib']
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
19
|
|
|
20
|
-
spec.add_runtime_dependency 'activerecord', '>= 7.
|
|
20
|
+
spec.add_runtime_dependency 'activerecord', '>= 7.2'
|
|
21
21
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seed-snapshot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yo_waka
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '7.
|
|
18
|
+
version: '7.2'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '7.
|
|
25
|
+
version: '7.2'
|
|
26
26
|
description: Easy dump/restore tool for ActiveRecord.
|
|
27
27
|
email:
|
|
28
28
|
- y.wakahara@gmail.com
|
|
@@ -31,23 +31,24 @@ extensions: []
|
|
|
31
31
|
extra_rdoc_files: []
|
|
32
32
|
files:
|
|
33
33
|
- ".github/workflows/main.yml"
|
|
34
|
+
- ".github/workflows/release.yml"
|
|
34
35
|
- ".gitignore"
|
|
36
|
+
- AGENTS.md
|
|
35
37
|
- Gemfile
|
|
36
38
|
- LICENSE.txt
|
|
37
39
|
- README.md
|
|
38
40
|
- Rakefile
|
|
39
41
|
- bin/console
|
|
40
42
|
- bin/setup
|
|
41
|
-
-
|
|
42
|
-
- gemfiles/ar_7.1.gemfile
|
|
43
|
+
- compose.yaml
|
|
43
44
|
- gemfiles/ar_7.2.gemfile
|
|
44
45
|
- gemfiles/ar_8.0.gemfile
|
|
46
|
+
- gemfiles/ar_8.1.gemfile
|
|
45
47
|
- lib/seed-snapshot.rb
|
|
46
48
|
- lib/seed/configuration.rb
|
|
47
49
|
- lib/seed/manifest.rb
|
|
48
50
|
- lib/seed/mysql.rb
|
|
49
51
|
- lib/seed/snapshot.rb
|
|
50
|
-
- lib/seed/version.rb
|
|
51
52
|
- lib/seed_snapshot/version.rb
|
|
52
53
|
- seed-snapshot.gemspec
|
|
53
54
|
homepage: https://github.com/waka/seed-snapshot
|
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
69
|
- !ruby/object:Gem::Version
|
|
69
70
|
version: '0'
|
|
70
71
|
requirements: []
|
|
71
|
-
rubygems_version:
|
|
72
|
+
rubygems_version: 4.0.20
|
|
72
73
|
specification_version: 4
|
|
73
74
|
summary: Easy dump/restore tool for ActiveRecord.
|
|
74
75
|
test_files: []
|
data/gemfiles/ar_7.1.gemfile
DELETED
data/lib/seed/version.rb
DELETED