rails_age 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -10
- data/lib/rails_age/version.rb +1 -1
- data/lib/tasks/add_age_migration.rake +69 -0
- data/lib/tasks/install.rake +2 -6
- data/lib/tasks/override_db_migrate.rake +50 -0
- metadata +4 -4
- data/lib/tasks/config_migrate.rake +0 -35
- data/lib/tasks/copy_migrations.rake +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e419984be6f29b1da74d0de6e31ccb218ba966e3818537884fcff715024e02
|
4
|
+
data.tar.gz: cb5a30c1e17ee7bf30394691232e3185e317ef5e827ece3ab02ef7d14cb0aef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555b80c544a8d5217d5c40ef3f24c15cd8fbf0c13bf96d1445845d9afc21d5e2ab835a60ac678ba5177fa5562ef1b87d7f293226783c94f1470d8b64e7a56fd9
|
7
|
+
data.tar.gz: 303f2776ebc5320711f50ec54e9a136ba7d9727fcb28c8d0038ffdcb0edb94d6715b93f40598a70d3eb3b8f1405a05610a707458f91209288414f0a4a7251374
|
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## VERSION 0.5.
|
4
|
-
|
5
|
-
- **AGE Schema override** (instance and class methods) assumes db and migrations up-to-date
|
3
|
+
## VERSION 0.5.1 - 2024-xx-xx
|
6
4
|
|
7
|
-
- **cypher**
|
5
|
+
- **cypher queries** (like active record queries)
|
8
6
|
* schema override
|
9
7
|
* query support
|
10
8
|
* paths support
|
11
9
|
* select attributes support
|
12
10
|
|
13
|
-
-
|
11
|
+
## VERSION 0.5.0 - 2024-xx-xx
|
12
|
+
|
13
|
+
- **Age Path**
|
14
|
+
|
15
|
+
## VERSION 0.4.3 - 2024-xx-xx
|
16
|
+
|
17
|
+
- **AGE Schema override**
|
18
|
+
|
19
|
+
- **multiple AGE Schema**
|
14
20
|
|
15
|
-
## VERSION 0.4.
|
21
|
+
## VERSION 0.4.3 - 2024-xx-xx
|
16
22
|
|
17
23
|
- **Edge Scaffold** (generates edge, type, view and controller)
|
18
24
|
* add `rails generate apache_age:edge_scaffold HasJob employee_role start_node:person end_node:company`
|
19
25
|
|
20
|
-
## VERSION 0.4.
|
26
|
+
## VERSION 0.4.2 - 2024-xx-xx
|
21
27
|
|
22
28
|
- **Node Scaffold** (generates node, type, view and controller)
|
23
29
|
* add `rails generate apache_age:node_scaffold Person first_name last_name age:integer`
|
@@ -29,10 +35,11 @@
|
|
29
35
|
* add `rails generate apache_age:edge HasPet owner_role start_node:person end_node:pet`
|
30
36
|
with property and specified start-/end-nodes (person and pet nodes must have already been created)
|
31
37
|
|
32
|
-
## VERSION 0.4.1 - 2024-
|
38
|
+
## VERSION 0.4.1 - 2024-06-15
|
33
39
|
|
34
|
-
- **
|
35
|
-
* add
|
40
|
+
- **Installer**
|
41
|
+
* add optional: safe migrations with `bin/rails db:migrate` instead of using `bin/rails apache_age:migrate`
|
42
|
+
(install using `bin/rails apache_age:override_db_migrate`)
|
36
43
|
|
37
44
|
## VERSION 0.4.0 - 2024-06-14
|
38
45
|
|
data/lib/rails_age/version.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# lib/tasks/install.rake
|
2
|
+
# Usage:
|
3
|
+
# * `bin/rails apache_age:add_age_migration`
|
4
|
+
# * `bin/rails apache_age:add_age_migration[destination_path.to_s]`
|
5
|
+
# * `bundle exec rails apache_age:add_age_migration.invoke(destination_path.to_s)`
|
6
|
+
namespace :apache_age do
|
7
|
+
desc "Copy migrations from rails_age to application and update schema"
|
8
|
+
task :add_age_migration, [:destination_path] => :environment do |t, args|
|
9
|
+
|
10
|
+
base_name = 'add_apache_age'
|
11
|
+
destination_path =
|
12
|
+
File.expand_path(args[:destination_path].presence || "#{Rails.root}/db/migrate", __FILE__)
|
13
|
+
|
14
|
+
FileUtils.mkdir_p(destination_path) unless File.exist?(destination_path)
|
15
|
+
existing_migrations =
|
16
|
+
Dir.glob("#{destination_path}/*.rb").map { |file| File.basename(file).sub(/^\d+/, '') }
|
17
|
+
|
18
|
+
if existing_migrations.any? { |migration| migration.include?(base_name) }
|
19
|
+
puts "Skipping migration AddApacheAge, it already exists"
|
20
|
+
else
|
21
|
+
age_migration_contents =
|
22
|
+
<<~RUBY
|
23
|
+
class AddApacheAge < ActiveRecord::Migration[7.1]
|
24
|
+
def up
|
25
|
+
# Allow age extension
|
26
|
+
execute('CREATE EXTENSION IF NOT EXISTS age;')
|
27
|
+
|
28
|
+
# Load the age code
|
29
|
+
execute("LOAD 'age';")
|
30
|
+
|
31
|
+
# Load the ag_catalog into the search path
|
32
|
+
execute('SET search_path = ag_catalog, "$user", public;')
|
33
|
+
|
34
|
+
# Create age_schema graph if it doesn't exist
|
35
|
+
execute("SELECT create_graph('age_schema');")
|
36
|
+
end
|
37
|
+
|
38
|
+
def down
|
39
|
+
execute <<-SQL
|
40
|
+
DO $$
|
41
|
+
BEGIN
|
42
|
+
IF EXISTS (
|
43
|
+
SELECT 1
|
44
|
+
FROM pg_constraint
|
45
|
+
WHERE conname = 'fk_graph_oid'
|
46
|
+
) THEN
|
47
|
+
ALTER TABLE ag_catalog.ag_label
|
48
|
+
DROP CONSTRAINT fk_graph_oid;
|
49
|
+
END IF;
|
50
|
+
END $$;
|
51
|
+
SQL
|
52
|
+
|
53
|
+
execute("SELECT drop_graph('age_schema', true);")
|
54
|
+
execute('DROP SCHEMA IF EXISTS ag_catalog CASCADE;')
|
55
|
+
execute('DROP EXTENSION IF EXISTS age;')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RUBY
|
59
|
+
|
60
|
+
migration_version = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
61
|
+
file_version = migration_version.delete('_')
|
62
|
+
new_filename = "#{file_version}_#{base_name}.rb"
|
63
|
+
destination_file = File.join(destination_path, new_filename)
|
64
|
+
|
65
|
+
File.write(destination_file, age_migration_contents)
|
66
|
+
puts "Created migration AddApacheAge"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/tasks/install.rake
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
namespace :apache_age do
|
5
5
|
desc "Install & configure Apache Age within Rails (updates migrations, schema & database.yml)"
|
6
6
|
task :install => :environment do
|
7
|
-
#
|
8
|
-
Rake::Task["apache_age:
|
7
|
+
# Ensure the AGE migration is in place
|
8
|
+
Rake::Task["apache_age:add_age_migration"].invoke
|
9
9
|
|
10
10
|
# run any new migrations
|
11
11
|
Rake::Task["db:migrate"].invoke
|
@@ -18,9 +18,5 @@ namespace :apache_age do
|
|
18
18
|
|
19
19
|
# ensure the config/initializers/types.rb file has the base AGE Types
|
20
20
|
Rake::Task["apache_age:config_types"].invoke
|
21
|
-
|
22
|
-
# # ensure bin/rails db:migrate is always followed with
|
23
|
-
# # `Rake::Task["apache_age:config_schema"].invoke` to ensure the schema isn't mangled
|
24
|
-
# Rake::Task["apache_age:config_migrate"].invoke
|
25
21
|
end
|
26
22
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
namespace :apache_age do
|
2
|
+
desc "Ensure 'db:migrate' is followed by 'apache_age:config_schema' to repair the schema.rb file after migration mangles it."
|
3
|
+
task :override_db_migrate, [:destination_path] => :environment do |t, args|
|
4
|
+
destination_path = (args[:destination_path].presence || "#{Rails.root}") + "/bin"
|
5
|
+
FileUtils.mkdir_p(destination_path) unless File.exist?(destination_path)
|
6
|
+
bin_rails_path = File.expand_path("#{destination_path}/rails", __FILE__)
|
7
|
+
|
8
|
+
original_content = File.read(bin_rails_path)
|
9
|
+
destination_content = original_content.dup
|
10
|
+
|
11
|
+
unless destination_content.include?("#!/usr/bin/env ruby\nrails_cmd = ARGV.first")
|
12
|
+
capture_rails_cmd =
|
13
|
+
<<~RUBY
|
14
|
+
rails_cmd = ARGV.first # must be first (otherwise consumed by rails:commands)
|
15
|
+
RUBY
|
16
|
+
|
17
|
+
# add to the top of the file (with gsub)
|
18
|
+
destination_content.sub!(
|
19
|
+
%r{#!/usr/bin/env ruby\n},
|
20
|
+
"#!/usr/bin/env ruby\n#{capture_rails_cmd}\n"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Check if the migration hook is already present
|
25
|
+
unless destination_content.include?('Rake::Task["apache_age:config_schema"].invoke')
|
26
|
+
override_migrate =
|
27
|
+
<<~RUBY
|
28
|
+
|
29
|
+
# ensure db:migrate is followed with: `Rake::Task["apache_age:config_schema"].invoke`
|
30
|
+
# to the schema.rb file after the migration mangles it
|
31
|
+
if rails_cmd == 'db:migrate'
|
32
|
+
require 'rake'
|
33
|
+
Rails.application.load_tasks
|
34
|
+
Rake::Task['db:migrate'].invoke
|
35
|
+
Rake::Task["apache_age:config_schema"].invoke
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
|
39
|
+
# append to the end of the file
|
40
|
+
destination_content << override_migrate
|
41
|
+
end
|
42
|
+
|
43
|
+
if destination_content == original_content
|
44
|
+
puts "AGE Safe Migration is already present in bin/rails. (If its not working inspect the bin/rails file)"
|
45
|
+
else
|
46
|
+
File.write(bin_rails_path, destination_content)
|
47
|
+
puts "AGE Safe Migration added to bin/rails. Now run `bin/rails db:migrate`, then run your tests (or inspect the schema.rb file)."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_age
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,13 +85,13 @@ files:
|
|
85
85
|
- lib/rails_age.rb
|
86
86
|
- lib/rails_age/engine.rb
|
87
87
|
- lib/rails_age/version.rb
|
88
|
+
- lib/tasks/add_age_migration.rake
|
88
89
|
- lib/tasks/config_database.rake
|
89
|
-
- lib/tasks/config_migrate.rake
|
90
90
|
- lib/tasks/config_schema.rake
|
91
91
|
- lib/tasks/config_types.rake
|
92
|
-
- lib/tasks/copy_migrations.rake
|
93
92
|
- lib/tasks/install.rake
|
94
93
|
- lib/tasks/migrate.rake
|
94
|
+
- lib/tasks/override_db_migrate.rake
|
95
95
|
homepage: https://github.com/marpori/rails_age
|
96
96
|
licenses:
|
97
97
|
- MIT
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# namespace :apache_age do
|
2
|
-
# desc "Ensure db:migrate is followed by apache_age:config_schema"
|
3
|
-
# task :config_migrate do
|
4
|
-
# bin_rails_path = File.expand_path('../../../bin/rails', __FILE__)
|
5
|
-
# migration_hook =
|
6
|
-
# <<-RUBY
|
7
|
-
# # ensure db:migrate is followed with: `Rake::Task["apache_age:config_schema"].invoke`
|
8
|
-
# # which repairs the schema.rb file after the migration mangles it
|
9
|
-
# require_relative '../config/boot'
|
10
|
-
# require 'rails/commands'
|
11
|
-
|
12
|
-
# if ARGV.first == 'db:migrate'
|
13
|
-
# require 'rake'
|
14
|
-
# Rails.application.load_tasks
|
15
|
-
# Rake::Task['db:migrate'].invoke
|
16
|
-
# Rake::Task["apache_age:config_schema"].invoke
|
17
|
-
# else
|
18
|
-
# Rake::Task['rails:commands'].invoke(*ARGV)
|
19
|
-
# end
|
20
|
-
# RUBY
|
21
|
-
|
22
|
-
# # Read the current content of the bin/rails file
|
23
|
-
# bin_rails_content = File.read(bin_rails_path)
|
24
|
-
|
25
|
-
# # Check if the migration hook is already present
|
26
|
-
# unless bin_rails_content.include?('Rake::Task["apache_age:config_schema"].invoke')
|
27
|
-
# # Append the migration hook to the end of the bin/rails file
|
28
|
-
# File.open(bin_rails_path, 'a') do |file|
|
29
|
-
# file.write(migration_hook)
|
30
|
-
# end
|
31
|
-
# puts "Migration hook added to bin/rails."
|
32
|
-
# else
|
33
|
-
# puts "Migration hook already present in bin/rails."
|
34
|
-
# end
|
35
|
-
# end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# lib/tasks/install.rake
|
2
|
-
# Usage:
|
3
|
-
# * `bin/rails apache_age:copy_migrations`
|
4
|
-
# * `bundle exec rails apache_age:copy_migrations[destination_path.to_s]`
|
5
|
-
# * `bundle exec rails apache_age:copy_migrations.invoke(destination_path.to_s)`
|
6
|
-
namespace :apache_age do
|
7
|
-
desc "Copy migrations from rails_age to application and update schema"
|
8
|
-
task :copy_migrations, [:destination_path] => :environment do |t, args|
|
9
|
-
source = File.expand_path('../../../db/migrate', __FILE__)
|
10
|
-
destination_path =
|
11
|
-
File.expand_path(args[:destination_path].presence || "#{Rails.root}/db/migrate", __FILE__)
|
12
|
-
|
13
|
-
FileUtils.mkdir_p(destination_path) unless File.exist?(destination_path)
|
14
|
-
existing_migrations =
|
15
|
-
Dir.glob("#{destination_path}/*.rb").map { |file| File.basename(file).sub(/^\d+/, '') }
|
16
|
-
|
17
|
-
Dir.glob("#{source}/*.rb").each do |file|
|
18
|
-
filename = File.basename(file)
|
19
|
-
test_name = filename.sub(/^\d+/, '')
|
20
|
-
|
21
|
-
if existing_migrations.include?(test_name)
|
22
|
-
puts "Skipping migration: '#{filename}', it already exists"
|
23
|
-
else
|
24
|
-
migration_version = Time.now.utc.strftime("%Y_%m_%d_%H%M%S")
|
25
|
-
file_version = migration_version.delete('_')
|
26
|
-
new_filename = filename.sub(/^\d+/, file_version)
|
27
|
-
destination_file = File.join(destination_path, new_filename)
|
28
|
-
FileUtils.cp(file, destination_file)
|
29
|
-
puts "Created migration: '#{new_filename}'"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|