prick 0.19.0 → 0.20.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -6
  3. data/README.md +7 -7
  4. data/Rakefile +3 -1
  5. data/TODO +13 -11
  6. data/bin/console +2 -1
  7. data/doc/build-yml.txt +14 -0
  8. data/exe/prick +237 -19
  9. data/lib/builder/batch.rb +147 -0
  10. data/lib/builder/builder.rb +122 -0
  11. data/lib/builder/node.rb +189 -0
  12. data/lib/builder/node_pool.rb +105 -0
  13. data/lib/builder/parser.rb +120 -0
  14. data/lib/local/command.rb +193 -0
  15. data/lib/{prick → local}/git.rb +148 -22
  16. data/lib/local/timer.rb +98 -0
  17. data/lib/prick/constants.rb +54 -66
  18. data/lib/prick/diff.rb +28 -18
  19. data/lib/prick/prick_version.rb +161 -0
  20. data/lib/prick/state.rb +80 -165
  21. data/lib/prick/version.rb +2 -163
  22. data/lib/prick.rb +38 -24
  23. data/lib/share/init/.gitignore +10 -0
  24. data/lib/share/init/.prick-context +2 -0
  25. data/lib/share/init/.rspec +3 -0
  26. data/{share/schema/schema/public → lib/share/init/migration}/.keep +0 -0
  27. data/lib/share/init/prick.yml +6 -0
  28. data/lib/share/init/schema/.keep +0 -0
  29. data/lib/share/init/schema/build.yml +2 -0
  30. data/lib/share/init/schema/prick/.keep +0 -0
  31. data/lib/share/init/schema/prick/build.yml +5 -0
  32. data/lib/share/init/schema/prick/data.sql +6 -0
  33. data/{share/schema → lib/share/init}/schema/prick/tables.sql +2 -3
  34. data/lib/share/init/schema/public/.keep +0 -0
  35. data/lib/share/init/spec/prick_helper.rb +1 -0
  36. data/lib/share/init/spec/prick_spec.rb +6 -0
  37. data/lib/share/init/spec/spec_helper.rb +50 -0
  38. data/lib/share/migrate/migration/build.yml +4 -0
  39. data/lib/share/migrate/migration/diff.after-tables.sql +0 -0
  40. data/lib/share/migrate/migration/diff.before-tables.sql +0 -0
  41. data/lib/share/migrate/migration/diff.tables.sql +0 -0
  42. data/lib/subcommand/prick-build.rb +55 -0
  43. data/lib/subcommand/prick-create.rb +78 -0
  44. data/lib/subcommand/prick-drop.rb +25 -0
  45. data/lib/subcommand/prick-fox.rb +62 -0
  46. data/lib/subcommand/prick-init.rb +46 -0
  47. data/lib/subcommand/prick-make.rb +202 -0
  48. data/lib/subcommand/prick-migrate.rb +37 -0
  49. data/lib/subcommand/prick-release.rb +23 -0
  50. data/lib/subcommand/prick-setup.rb +20 -0
  51. data/lib/subcommand/prick-teardown.rb +18 -0
  52. data/prick.gemspec +23 -31
  53. metadata +69 -78
  54. data/.gitignore +0 -29
  55. data/.travis.yml +0 -7
  56. data/doc/create_release.txt +0 -17
  57. data/doc/flow.txt +0 -98
  58. data/doc/migra +0 -1
  59. data/doc/migrations.txt +0 -172
  60. data/doc/notes.txt +0 -116
  61. data/doc/prick.txt +0 -114
  62. data/doc/sh.prick +0 -316
  63. data/lib/ext/algorithm.rb +0 -14
  64. data/lib/ext/fileutils.rb +0 -26
  65. data/lib/ext/forward_method.rb +0 -18
  66. data/lib/ext/pg.rb +0 -18
  67. data/lib/ext/shortest_path.rb +0 -44
  68. data/lib/prick/archive.rb +0 -124
  69. data/lib/prick/branch.rb +0 -265
  70. data/lib/prick/builder.rb +0 -246
  71. data/lib/prick/cache.rb +0 -34
  72. data/lib/prick/command.rb +0 -104
  73. data/lib/prick/database.rb +0 -82
  74. data/lib/prick/dsort.rb +0 -151
  75. data/lib/prick/ensure.rb +0 -119
  76. data/lib/prick/exceptions.rb +0 -25
  77. data/lib/prick/head.rb +0 -189
  78. data/lib/prick/migration.rb +0 -70
  79. data/lib/prick/program.rb +0 -287
  80. data/lib/prick/project.rb +0 -626
  81. data/lib/prick/rdbms.rb +0 -137
  82. data/lib/prick/schema.rb +0 -27
  83. data/lib/prick/share.rb +0 -64
  84. data/libexec/strip-comments +0 -33
  85. data/make_releases +0 -72
  86. data/make_schema +0 -10
  87. data/share/diff/diff.after-tables.sql +0 -4
  88. data/share/diff/diff.before-tables.sql +0 -4
  89. data/share/diff/diff.tables.sql +0 -8
  90. data/share/features/diff.sql +0 -2
  91. data/share/features/feature/diff.sql +0 -2
  92. data/share/features/feature/migrate.sql +0 -2
  93. data/share/features/features.sql +0 -2
  94. data/share/features/features.yml +0 -2
  95. data/share/features/migrations.sql +0 -4
  96. data/share/gitignore +0 -2
  97. data/share/migration/diff.tables.sql +0 -8
  98. data/share/migration/features.yml +0 -6
  99. data/share/migration/migrate.sql +0 -3
  100. data/share/migration/migrate.yml +0 -8
  101. data/share/migration/tables.sql +0 -3
  102. data/share/schema/build.yml +0 -14
  103. data/share/schema/schema/build.yml +0 -3
  104. data/share/schema/schema/prick/build.yml +0 -14
  105. data/share/schema/schema/prick/data.sql +0 -7
  106. data/share/schema/schema/prick/schema.sql +0 -3
  107. data/share/schema/schema/public/build.yml +0 -13
  108. data/share/schema/schema.sql +0 -3
  109. data/test_assorted +0 -192
  110. data/test_feature +0 -112
  111. data/test_refactor +0 -34
  112. data/test_single_dev +0 -83
data/lib/prick/rdbms.rb DELETED
@@ -1,137 +0,0 @@
1
- require 'prick/command.rb'
2
-
3
- require 'csv'
4
-
5
- module Prick
6
- module Rdbms
7
- ### EXECUTE SQL
8
-
9
- # Execute the SQL statement and return stdout as an array of tuples
10
- def self.exec_sql(db, sql, user: ENV['USER'], schema: nil)
11
- schema ||= "public"
12
- stdout = Command.command %(
13
- {
14
- echo "set role #{user};"
15
- echo "set search_path to #{schema};"
16
- cat <<'EOF'
17
- #{sql}
18
- EOF
19
- } | psql --csv --tuples-only --quiet -v ON_ERROR_STOP=1 -d #{db}
20
- )
21
- CSV.new(stdout.join("\n")).read
22
- end
23
-
24
- # Execute the given file and return stdout as an array of tuples
25
- def self.exec_file(db, file, user: ENV['USER'], schema: nil)
26
- self.exec_sql(db, File.read(file), user: user, schema: schema)
27
- end
28
-
29
- # Execute the SQL statement and return the result as an array of record tuples
30
- # Just an alias for ::exec_sql
31
- def self.select(db, sql, user: ENV['USER']) exec_sql(db, sql, user: user) end
32
-
33
- # Execute the SQL statement and return an array of values, one for each
34
- # single-valued record in the result. Raises an exception if the SQL
35
- # statement doesn't return records with exactly one field
36
- def self.select_values(db, sql, user: ENV['USER'])
37
- records = exec_sql(db, sql, user: user)
38
- return [] if records.empty?
39
- records.first.size == 1 or raise Prick::Fail, "Expected records with one field"
40
- records.flatten
41
- end
42
-
43
- # Execute the SQL statement and return a single record as an array of values.
44
- # Raises an exception if the SQL statement doesn't return exactly one
45
- # record
46
- def self.select_record(db, sql, user: ENV['USER'])
47
- records = exec_sql(db, sql, user: user)
48
- records.size == 1 or raise Prick::Fail, "Expected one row only"
49
- records.first
50
- end
51
-
52
- # Execute the SQL statement and return a value. The value is the first
53
- # field of the first record in the result. Raises an exception if the SQL
54
- # statement doesn't return exactly one record with one field
55
- def self.select_value(db, sql, user: ENV['USER'])
56
- row = select_record(db, sql, user: user)
57
- row.size == 1 or raise Prick::Fail, "Expected one field only"
58
- row.first
59
- end
60
-
61
- ### DETECT SCHEMAS, TABLES, AND RECORDS
62
-
63
- def self.exist_schema?(db, schema)
64
- exist_record?(db, %(
65
- select 1
66
- from information_schema.schemata
67
- where catalog_name = '#{db}'
68
- and schema_name = '#{schema}'
69
- ))
70
- end
71
-
72
- def self.exist_table?(db, schema, table)
73
- exist_record?(db, %(
74
- select 1
75
- from information_schema.tables
76
- where table_schema = '#{schema}'
77
- and table_name = '#{table}'
78
- ))
79
- end
80
-
81
- def self.exist_record?(db, sql)
82
- !select(db, sql).empty?
83
- end
84
-
85
- ### MAINTAIN USERS AND DATABASES
86
-
87
- def self.exist_user?(user)
88
- exist_record?("template1", "select 1 from pg_roles where rolname = '#{user}'")
89
- end
90
-
91
- def self.create_user(user)
92
- Command.command("createuser #{user}")
93
- end
94
-
95
- def self.drop_user(user, fail: true)
96
- Command.command "dropuser #{user}", fail: fail
97
- end
98
-
99
- def self.exist_database?(db)
100
- exist_record?("template1", "select 1 from pg_database where datname = '#{db}'")
101
- end
102
-
103
- # TODO: make `owner` an option
104
- def self.create_database(db, owner: ENV['USER'], template: "template1")
105
- owner_option = (owner ? "-O #{owner}" : "")
106
- Command.command "createdb -T #{template} #{owner_option} #{db}"
107
- end
108
-
109
- def self.copy_database(from, to, owner: ENV['USER'])
110
- create_database(to, owner: owner, template: from)
111
- end
112
-
113
- def self.drop_database(db, fail: true)
114
- Command.command "dropdb #{db}", fail: fail
115
- end
116
-
117
- def self.list_databases(re = /.*/)
118
- select_values("template1", "select datname from pg_database").select { |db| db =~ re }
119
- end
120
-
121
- def self.load(db, file, user: ENV['USER'])
122
- Command.command %(
123
- {
124
- echo "set role #{user};"
125
- gunzip --to-stdout #{file}
126
- } | psql -v ON_ERROR_STOP=1 -d #{db}
127
- )
128
- end
129
-
130
- def self.save(db, file, data: true)
131
- data_opt = (data ? "" : "--schema-only")
132
- Command.command "pg_dump --no-owner #{data_opt} #{db} | gzip --to-stdout >#{file}"
133
- end
134
- end
135
- end
136
-
137
-
data/lib/prick/schema.rb DELETED
@@ -1,27 +0,0 @@
1
- require "prick/state.rb"
2
-
3
- module Prick
4
- PRICK_SCHEMA = "prick"
5
- SCHEMA_NAMES = %w(schema roles types tables data constraints indexes views functions comments grants)
6
- BUILD_BASE_NAME = "build"
7
- BUILD_SQL_FILE = BUILD_BASE_NAME + ".sql"
8
- BUILD_YML_FILE = BUILD_BASE_NAME + ".yml"
9
-
10
- # Note this models the SCHEMA_DIR directory, not a database schema
11
- class Schema
12
- def yml_file() self.class.yml_file end
13
- def self.yml_file() SchemaBuilder.yml_file(SCHEMA_DIR) end
14
-
15
- def version() SchemaVersion.load end
16
- def version=(version) SchemaVersion.new(version).write end
17
- def version_file() SchemaVersion.new.path end
18
-
19
- def built?(database) database.exist? && database.version == version end
20
-
21
- # `subject` can be a subpath of schema/ (ie. 'public/tables')
22
- def build(database, subject = nil)
23
- SchemaBuilder.new(database, SCHEMA_DIR).build(subject)
24
- end
25
- end
26
- end
27
-
data/lib/prick/share.rb DELETED
@@ -1,64 +0,0 @@
1
-
2
- module Prick
3
- class Share
4
- # Procedural object for templating and copying share/ files
5
- class Copier
6
- attr_reader :clobber, :templates
7
-
8
- def initialize(clobber, templates)
9
- @clobber = clobber
10
- @templates = templates
11
- end
12
-
13
- def cp(from, to)
14
- if File.directory?(from)
15
- cp_dir(from, to)
16
- elsif File.file?(from)
17
- cp_file(from, to)
18
- else
19
- raise Fail, "Can't copy #{from}"
20
- end
21
- end
22
-
23
- def cp_file(from, to)
24
- if clobber || !File.exist?(to)
25
- if templates.empty?
26
- FileUtils.copy_file(from, to)
27
- else
28
- File.open(to, "w") { |f|
29
- File.readlines(from).each { |l|
30
- templates.each { |key, value| l.gsub!(/\[<#{key}>\]/, value) }
31
- f.puts l
32
- }
33
- }
34
- end
35
- [to]
36
- else
37
- []
38
- end
39
- end
40
-
41
- def cp_dir(from, to)
42
- FileUtils.mkdir_p(to)
43
- Dir.children(from).map { |name|
44
- cp(File.join(from, name), File.join(to, name))
45
- }.flatten
46
- end
47
- end
48
-
49
- def self.cp(pattern, dest, clobber: true, templates: {})
50
- copier = Copier.new(clobber, templates)
51
- matches = Dir.glob(File.join(SHARE_PATH, pattern))
52
- if File.directory?(dest)
53
- matches.map { |from| copier.cp(from, File.join(dest, File.basename(from))) }.flatten
54
- elsif matches.size == 1
55
- copier.cp(matches.first, dest)
56
- elsif matches.size == 0
57
- []
58
- else
59
- raise Internal, "Destination is not a directory: #{destdir}"
60
- end
61
- end
62
- end
63
- end
64
-
@@ -1,33 +0,0 @@
1
- #!/usr/bin/bash
2
-
3
- # NAME
4
- # strip-comments - Remove comments from postgres files
5
- #
6
- # USAGE
7
- # strip-comments [FILE]
8
- #
9
- # DESCRIPTION
10
- # Remove comments and blank lines from standard intput or the given file and
11
- # write the result on standard output
12
- #
13
- # REFERENCES
14
- # https://stackoverflow.com/a/35708616/1745001
15
- #
16
-
17
- PROGRAM=$(basename $0)
18
- USAGE="[FILE]"
19
-
20
- function error() {
21
- echo "$PROGRAM: $@"
22
- echo "Usage: $PROGRAM $USAGE"
23
- exit 1
24
- } >&2
25
-
26
- [ $# -le 1 ] || error "Illegal number of arguments"
27
- FILE=$1
28
-
29
- sed '/^\s*--/d' $FILE \
30
- | sed 's/a/aA/g; s/__/aB/g; s/#/aC/g' \
31
- | gcc -P -E -ansi - \
32
- | sed 's/aC/#/g; s/aB/__/g; s/aA/a/g'
33
-
data/make_releases DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/bash
2
-
3
- set -e
4
-
5
- rm -rf dir
6
- echo "Initialize prick"
7
- echo
8
- prick --name prj init dir
9
- (
10
- cd dir
11
-
12
- echo "Prepare an unnamed release"
13
- prick prepare
14
- echo
15
-
16
- echo "Create release 0.0.1"
17
- prick create release 0.0.1
18
- echo
19
-
20
- echo "Create feature_a"
21
- prick create feature feature_a
22
- echo
23
-
24
- echo "Update schema"
25
- echo "create table t (id integer)" >> schemas/public/schema.sql
26
- git add schemas/public/schema.sql
27
- git commit -m "Added PUBLIC.T"
28
-
29
- echo "Build branch"
30
- prick build
31
- psql -d prj -c "select version from prick.versions"
32
-
33
- exit
34
-
35
- echo "Create prerelease 0.1.0.pre.1"
36
- prick create prerelease minor
37
- echo
38
-
39
- echo "Increment prerelease"
40
- prick create prerelease
41
- echo
42
-
43
- echo "Release (0.1.0)"
44
- prick create release
45
- echo
46
-
47
- echo "Create release 0.2.0"
48
- prick create release 0.2.0
49
- echo
50
-
51
- echo "Prepare migration"
52
- prick prepare migration 0.0.0
53
- echo
54
-
55
- echo "Create migration"
56
- prick create migration
57
- echo
58
-
59
- # echo "Create release 0.3.0"
60
- # git checkout 0.2.0
61
- # prick create release 0.3.0
62
- # echo
63
- #
64
- # echo "Retarget 0.0.0 -> 0.3.0"
65
- # git checkout 0.0.0_0.2.0
66
- # prick retarget 0.3.0
67
- # echo
68
-
69
- tree -a -I .git
70
- )
71
-
72
-
data/make_schema DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/bash
2
-
3
- SHARE_DIR=share/schemas/schema
4
- mkdir -p $SHARE_DIR
5
- NAMES="roles types tables data constraints indexes views functions comments grants"
6
- for name in $NAMES; do
7
- name=$name.sql
8
- file=$SHARE_DIR/$name
9
- echo -ne "-- ${name}\n\nset search_path to [<SCHEMA>];\n\n" >$file
10
- done
@@ -1,4 +0,0 @@
1
- -- Generated by prick(1) via migra(1). Please don't touch.
2
- --
3
- -- It should not be necessary to change this file as it doesn't contain data changes
4
- --
@@ -1,4 +0,0 @@
1
- -- Generated by prick(1) via migra(1). Please don't touch.
2
- --
3
- -- It should not be necessary to change this file as it doesn't contain data changes
4
- --
@@ -1,8 +0,0 @@
1
- -- Generated by prick(1) via migra(1). Please don't touch.
2
- --
3
- -- This file contains changes that can touch existing data in the database that
4
- -- needs speciel treatment in the migrate.sql
5
- --
6
- -- Note that this file is not executed by prick by default and that it is not
7
- -- added to the Git repo when it changes. You have to do that manually
8
- --
@@ -1,2 +0,0 @@
1
- -- Generated by migra(1). Please don't touch. Customize the migration in migrations.sql instead
2
- --
@@ -1,2 +0,0 @@
1
- -- Generated by migra(1). Please don't touch. Customize the migration in migrations.sql instead
2
- --
@@ -1,2 +0,0 @@
1
- -- Customize your migrations here
2
- --
@@ -1,2 +0,0 @@
1
- -- Auto-generated by prick(1). Please don't touch
2
- --
@@ -1,2 +0,0 @@
1
- # Auto-generated by prick(1). Please don't touch
2
- #
@@ -1,4 +0,0 @@
1
- -- Customize your migrations here
2
- --
3
- \i features.sql
4
-
data/share/gitignore DELETED
@@ -1,2 +0,0 @@
1
- /tmp/
2
- /var/
@@ -1,8 +0,0 @@
1
- -- Generated by prick(1) via migra(1). Please don't touch.
2
- --
3
- -- This file contains changes that can touch existing data in the database that
4
- -- needs speciel treatment in the migrate.sql
5
- --
6
- -- Note that this file is not executed by prick by default and that it is not
7
- -- added to the Git repo when it changes. You have to do that manually
8
- --
@@ -1,6 +0,0 @@
1
- # Auto-generated by prick(1). Please don't touch
2
- #
3
- # This file is auto-generated from the set of features.yml files in the
4
- # migration so that order of initialization is correct
5
- #
6
- ---
@@ -1,3 +0,0 @@
1
- -- Customize your migrations here but
2
- --
3
-
@@ -1,8 +0,0 @@
1
- # You can customize this file
2
- #
3
- ---
4
- - features
5
- - diff.before-tables.sql
6
- - tables
7
- - migrate.sql
8
- - diff.after-tables.sql
@@ -1,3 +0,0 @@
1
- -- Placeholder for table changes. After you prepared a diff, you should inspect
2
- -- diff.table.sql and incorporate the changes here
3
- --
@@ -1,14 +0,0 @@
1
- # Default schema files
2
- #
3
- ---
4
- - schema
5
- - roles
6
- - types
7
- - tables
8
- - data
9
- - constraints
10
- - indexes
11
- - views
12
- - functions
13
- - comments
14
- - grants
@@ -1,3 +0,0 @@
1
- ---
2
- - prick
3
- - public
@@ -1,14 +0,0 @@
1
- # Default schema files
2
- #
3
- ---
4
- - schema
5
- - roles
6
- - types
7
- - tables
8
- - data
9
- - constraints
10
- - indexes
11
- - views
12
- - functions
13
- - comments
14
- - grants
@@ -1,7 +0,0 @@
1
- -- Auto-generated file. Don't touch
2
- --
3
-
4
- COPY prick.versions (id, fork, major, minor, patch, pre, feature, version) FROM stdin;
5
- 1 \N 0 0 0 \N \N 0.0.0
6
- \.
7
-
@@ -1,3 +0,0 @@
1
-
2
- drop schema if exists prick cascade;
3
- create schema prick;
@@ -1,13 +0,0 @@
1
- # Default schema files
2
- #
3
- ---
4
- - roles
5
- - types
6
- - tables
7
- - data
8
- - constraints
9
- - indexes
10
- - views
11
- - functions
12
- - comments
13
- - grants
@@ -1,3 +0,0 @@
1
-
2
- drop schema if exists [<SCHEMA>] cascade;
3
- create schema [<SCHEMA>];