convergence 1.0.5 → 1.1.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +55 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +52 -0
  5. data/CONTRIBUTING.md +80 -0
  6. data/Gemfile.lock +24 -9
  7. data/README.md +131 -1
  8. data/Rakefile +48 -5
  9. data/convergence.gemspec +3 -1
  10. data/lib/convergence/cli.rb +10 -2
  11. data/lib/convergence/command/apply.rb +38 -9
  12. data/lib/convergence/command/dryrun.rb +5 -5
  13. data/lib/convergence/command/export.rb +19 -1
  14. data/lib/convergence/command.rb +6 -0
  15. data/lib/convergence/config.rb +1 -1
  16. data/lib/convergence/database_connector/postgres_connector.rb +25 -0
  17. data/lib/convergence/database_connector/sqlite_connector.rb +22 -0
  18. data/lib/convergence/database_connector.rb +6 -0
  19. data/lib/convergence/default_parameter/mysql_default_parameter.rb +1 -1
  20. data/lib/convergence/default_parameter/postgres_default_parameter.rb +57 -0
  21. data/lib/convergence/default_parameter/sqlite_default_parameter.rb +57 -0
  22. data/lib/convergence/default_parameter.rb +6 -0
  23. data/lib/convergence/diff.rb +9 -2
  24. data/lib/convergence/dsl.rb +18 -3
  25. data/lib/convergence/dumper/mysql_schema_dumper.rb +37 -9
  26. data/lib/convergence/dumper/postgres_schema_dumper.rb +193 -0
  27. data/lib/convergence/dumper/sqlite_schema_dumper.rb +132 -0
  28. data/lib/convergence/dumper.rb +113 -0
  29. data/lib/convergence/sql_generator/mysql_generator.rb +18 -3
  30. data/lib/convergence/sql_generator/postgres_generator.rb +256 -0
  31. data/lib/convergence/sql_generator/sqlite_generator.rb +178 -0
  32. data/lib/convergence/version.rb +1 -1
  33. data/spec/config/spec_database.yml +15 -2
  34. data/spec/convergence/config_spec.rb +75 -0
  35. data/spec/convergence/diff_spec.rb +125 -45
  36. data/spec/convergence/dsl_spec.rb +26 -0
  37. data/spec/convergence/dumper/mysql_schema_dumper_spec.rb +25 -2
  38. data/spec/convergence/dumper/postgres_schema_dumper_spec.rb +103 -0
  39. data/spec/convergence/dumper/sqlite_schema_dumper_spec.rb +85 -0
  40. data/spec/convergence/dumper_spec.rb +110 -16
  41. data/spec/convergence/foreign_key_spec.rb +33 -0
  42. data/spec/convergence/index_spec.rb +52 -0
  43. data/spec/convergence/pretty_diff_spec.rb +85 -0
  44. data/spec/convergence/table_spec.rb +23 -0
  45. data/spec/fixtures/add_table_with_enum_set.schema +5 -0
  46. data/spec/fixtures/change_table_comment_to_paper.schema +2 -0
  47. data/spec/fixtures/execute_raw_sql.schema +28 -0
  48. data/spec/fixtures/postgres/add_columns_to_paper.schema +29 -0
  49. data/spec/fixtures/postgres/add_table.schema +32 -0
  50. data/spec/fixtures/postgres/change_comment_columns_to_paper.schema +28 -0
  51. data/spec/fixtures/postgres/change_table_comment_to_paper.schema +28 -0
  52. data/spec/fixtures/postgres/drop_foreign_key.schema +25 -0
  53. data/spec/fixtures/postgres/drop_table.schema +19 -0
  54. data/spec/fixtures/postgres/remove_columns_to_paper.schema +27 -0
  55. data/spec/fixtures/postgres_test_db.sql +41 -0
  56. data/spec/fixtures/sqlite/add_columns_to_paper.schema +29 -0
  57. data/spec/fixtures/sqlite/add_table.schema +32 -0
  58. data/spec/fixtures/sqlite/change_columns_to_paper.schema +28 -0
  59. data/spec/fixtures/sqlite/drop_foreign_key.schema +25 -0
  60. data/spec/fixtures/sqlite/drop_table.schema +19 -0
  61. data/spec/fixtures/sqlite/remove_columns_to_paper.schema +27 -0
  62. data/spec/fixtures/sqlite_test_db.sql +31 -0
  63. data/spec/fixtures/test_db.sql +10 -0
  64. data/spec/integrations/command_diff.rb +35 -0
  65. data/spec/integrations/command_dryrun.rb +37 -2
  66. data/spec/integrations/command_export.rb +28 -0
  67. data/spec/postgres_integrations/command_dryrun.rb +79 -0
  68. data/spec/spec_helper.rb +13 -0
  69. data/spec/sqlite_integrations/command_dryrun.rb +70 -0
  70. metadata +97 -9
  71. data/.travis.yml +0 -9
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'convergence/foreign_key'
3
+
4
+ describe Convergence::ForeignKey do
5
+ describe '#initialize' do
6
+ it 'wraps a single from_column/to_column into an array of strings' do
7
+ fk = Convergence::ForeignKey.new('fk_name', :author_id, 'authors', :id, {})
8
+ expect(fk.from_columns).to eq(['author_id'])
9
+ expect(fk.to_columns).to eq(['id'])
10
+ end
11
+
12
+ it 'wraps multiple from_columns/to_columns into arrays of strings' do
13
+ fk = Convergence::ForeignKey.new('fk_name', [:a_id, :b_id], 'targets', [:a, :b], {})
14
+ expect(fk.from_columns).to eq(['a_id', 'b_id'])
15
+ expect(fk.to_columns).to eq(['a', 'b'])
16
+ end
17
+
18
+ it 'stringifies the target table name' do
19
+ fk = Convergence::ForeignKey.new('fk_name', :author_id, :authors, :id, {})
20
+ expect(fk.to_table).to eq('authors')
21
+ end
22
+
23
+ it 'defaults the :name option to the key name' do
24
+ fk = Convergence::ForeignKey.new('fk_name', :author_id, 'authors', :id, {})
25
+ expect(fk.options[:name]).to eq('fk_name')
26
+ end
27
+
28
+ it 'preserves any additional options passed in' do
29
+ fk = Convergence::ForeignKey.new('fk_name', :author_id, 'authors', :id, on_delete: :cascade)
30
+ expect(fk.options[:on_delete]).to eq(:cascade)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'convergence/index'
3
+
4
+ describe Convergence::Index do
5
+ describe '#initialize' do
6
+ it 'defaults the :name option to the index name' do
7
+ index = Convergence::Index.new('idx_name', 'name', {})
8
+ expect(index.options[:name]).to eq('idx_name')
9
+ end
10
+
11
+ it 'wraps a single column into an array of strings' do
12
+ index = Convergence::Index.new('idx_name', :name, {})
13
+ expect(index.index_columns).to eq(['name'])
14
+ end
15
+
16
+ it 'wraps multiple columns into an array of strings' do
17
+ index = Convergence::Index.new('idx_name', [:first_name, :last_name], {})
18
+ expect(index.index_columns).to eq(['first_name', 'last_name'])
19
+ end
20
+
21
+ context 'when length is a single Integer' do
22
+ it 'applies it to every column' do
23
+ index = Convergence::Index.new('idx_name', [:first_name, :last_name], length: 10)
24
+ expect(index.options[:length]).to eq('first_name' => 10, 'last_name' => 10)
25
+ end
26
+ end
27
+
28
+ context 'when length is a Hash keyed by symbol' do
29
+ it 'normalizes the keys to strings' do
30
+ index = Convergence::Index.new('idx_name', [:first_name, :last_name], length: { first_name: 10, last_name: 20 })
31
+ expect(index.options[:length]).to eq('first_name' => 10, 'last_name' => 20)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#quoted_columns' do
37
+ it 'quotes each column name with backticks' do
38
+ index = Convergence::Index.new('idx_name', [:first_name, :last_name], {})
39
+ expect(index.quoted_columns).to eq(['`first_name`', '`last_name`'])
40
+ end
41
+
42
+ it 'appends the prefix length in parentheses when configured' do
43
+ index = Convergence::Index.new('idx_name', [:first_name, :last_name], length: { first_name: 10 })
44
+ expect(index.quoted_columns).to eq(['`first_name`(10)', '`last_name`'])
45
+ end
46
+
47
+ it 'escapes a backtick embedded in a column name' do
48
+ index = Convergence::Index.new('idx_name', 'weird`name', {})
49
+ expect(index.quoted_columns).to eq(['`weird``name`'])
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'convergence/pretty_diff'
3
+ require 'convergence/table'
4
+
5
+ describe Convergence::PrettyDiff do
6
+ describe '#output' do
7
+ context 'when a table is added' do
8
+ let(:from_tables) { {} }
9
+ let(:to_tables) do
10
+ { 'users' => Convergence::Table.new('users').tap { |t| t.int('id', primary_key: true) } }
11
+ end
12
+
13
+ it 'should show the added table with a + prefix on every line' do
14
+ output = Convergence::PrettyDiff.new(from_tables, to_tables).output
15
+ expect(output).to be_include('+ create_table :users do |t|')
16
+ expect(output).to be_include('+ t.int :id, primary_key: true')
17
+ expect(output).to be_include('+ end')
18
+ end
19
+ end
20
+
21
+ context 'when a table is removed' do
22
+ let(:from_tables) do
23
+ { 'users' => Convergence::Table.new('users').tap { |t| t.int('id', primary_key: true) } }
24
+ end
25
+ let(:to_tables) { {} }
26
+
27
+ it 'should show the removed table with a - prefix on every line' do
28
+ output = Convergence::PrettyDiff.new(from_tables, to_tables).output
29
+ expect(output).to be_include('- create_table :users do |t|')
30
+ expect(output).to be_include('- t.int :id, primary_key: true')
31
+ expect(output).to be_include('- end')
32
+ end
33
+ end
34
+
35
+ context 'when a table column is changed' do
36
+ let(:from_tables) do
37
+ { 'users' => Convergence::Table.new('users').tap { |t| t.varchar('name', limit: 100) } }
38
+ end
39
+ let(:to_tables) do
40
+ { 'users' => Convergence::Table.new('users').tap { |t| t.varchar('name', limit: 200) } }
41
+ end
42
+
43
+ it 'should show a unified diff of only the changed column' do
44
+ output = Convergence::PrettyDiff.new(from_tables, to_tables).output
45
+ expect(output).to be_include('- t.varchar :name, limit: 100')
46
+ expect(output).to be_include('+ t.varchar :name, limit: 200')
47
+ expect(output).to be_include(' create_table :users do |t|')
48
+ end
49
+ end
50
+
51
+ context 'when nothing changed' do
52
+ let(:tables) do
53
+ { 'users' => Convergence::Table.new('users').tap { |t| t.int('id', primary_key: true) } }
54
+ end
55
+
56
+ it 'should return an empty string' do
57
+ output = Convergence::PrettyDiff.new(tables, tables).output
58
+ expect(output).to eq('')
59
+ end
60
+ end
61
+
62
+ context 'when tables are added, removed, and changed at the same time' do
63
+ let(:from_tables) do
64
+ {
65
+ 'authors' => Convergence::Table.new('authors').tap { |t| t.int('id', primary_key: true) },
66
+ 'papers' => Convergence::Table.new('papers').tap { |t| t.varchar('title', limit: 100) }
67
+ }
68
+ end
69
+ let(:to_tables) do
70
+ {
71
+ 'papers' => Convergence::Table.new('papers').tap { |t| t.varchar('title', limit: 200) },
72
+ 'comments' => Convergence::Table.new('comments').tap { |t| t.int('id', primary_key: true) }
73
+ }
74
+ end
75
+
76
+ it 'should show every add/remove/change table diff' do
77
+ output = Convergence::PrettyDiff.new(from_tables, to_tables).output
78
+ expect(output).to be_include('+ create_table :comments do |t|')
79
+ expect(output).to be_include('- create_table :authors do |t|')
80
+ expect(output).to be_include('- t.varchar :title, limit: 100')
81
+ expect(output).to be_include('+ t.varchar :title, limit: 200')
82
+ end
83
+ end
84
+ end
85
+ end
@@ -28,6 +28,29 @@ describe Convergence::Table do
28
28
  end
29
29
  end
30
30
 
31
+ describe '#boolean' do
32
+ it 'should be stored as a tinyint(1) column' do
33
+ table.boolean(dummy_column)
34
+ expect(table.columns[dummy_column].type).to eq(:tinyint)
35
+ expect(table.columns[dummy_column].options[:limit]).to eq(1)
36
+ end
37
+
38
+ it 'should convert a true default to 1' do
39
+ table.boolean(dummy_column, default: true)
40
+ expect(table.columns[dummy_column].options[:default]).to eq(1)
41
+ end
42
+
43
+ it 'should convert a false default to 0' do
44
+ table.boolean(dummy_column, default: false)
45
+ expect(table.columns[dummy_column].options[:default]).to eq(0)
46
+ end
47
+
48
+ it 'should preserve other options' do
49
+ table.boolean(dummy_column, null: false)
50
+ expect(table.columns[dummy_column].options[:null]).to eq(false)
51
+ end
52
+ end
53
+
31
54
  describe '#index' do
32
55
  context 'when option name is nil' do
33
56
  it 'should generate index name' do
@@ -0,0 +1,5 @@
1
+ create_table 'enum_set_dummies' do |t|
2
+ t.int 'id', primary_key: true, extra: 'auto_increment'
3
+ t.enum 'status', values: %w(active inactive pending), default: 'active'
4
+ t.set 'flags', values: %w(a b c)
5
+ end
@@ -14,6 +14,8 @@ create_table "papers", collate: "utf8_general_ci", comment: "Paper" do |t|
14
14
  t.varchar "title1", limit: 300, comment: "Title 1"
15
15
  t.varchar "title2", limit: 300, comment: "Title 2"
16
16
  t.text "description", null: true, comment: "Description"
17
+ t.int "edition_number", default: 0
18
+ t.datetime "published_at", default: -> { "CURRENT_TIMESTAMP" }
17
19
  end
18
20
 
19
21
  create_table "paper_authors", collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|
@@ -0,0 +1,28 @@
1
+ create_table "authors", collate: "utf8_general_ci", comment: "" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age", unsigned: true
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", collate: "utf8_general_ci", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+ end
18
+
19
+ create_table "paper_authors", collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|
20
+ t.int "id", primary_key: true, extra: "auto_increment"
21
+ t.int "paper_id", comment: "Paper id"
22
+ t.int "author_id", comment: "Paper author id"
23
+
24
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
25
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
26
+ end
27
+
28
+ execute "UPDATE authors SET age = 0 WHERE age IS NULL"
@@ -0,0 +1,29 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+ t.varchar "subtitle", null: true, comment: "Subtitle"
18
+
19
+ t.index "slug", name: "index_papers_on_slug", unique: true
20
+ end
21
+
22
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
23
+ t.int "id", primary_key: true, extra: "auto_increment"
24
+ t.int "paper_id", comment: "Paper id"
25
+ t.int "author_id", comment: "Paper author id"
26
+
27
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
28
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
29
+ end
@@ -0,0 +1,32 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id", comment: "Paper id"
24
+ t.int "author_id", comment: "Paper author id"
25
+
26
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
27
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
28
+ end
29
+
30
+ create_table "dummies", comment: "Dummy Table" do |t|
31
+ t.int "id", primary_key: true, extra: "auto_increment", comment: "Hello Convergence"
32
+ end
@@ -0,0 +1,28 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true, comment: "Created At"
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id", comment: "Paper id"
24
+ t.int "author_id", comment: "Paper author id"
25
+
26
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
27
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
28
+ end
@@ -0,0 +1,28 @@
1
+ create_table "authors", comment: "Author Table" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id", comment: "Paper id"
24
+ t.int "author_id", comment: "Paper author id"
25
+
26
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
27
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
28
+ end
@@ -0,0 +1,25 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id", comment: "Paper id"
24
+ t.int "author_id", comment: "Paper author id"
25
+ end
@@ -0,0 +1,19 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+ t.text "description", null: true, comment: "Description"
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
@@ -0,0 +1,27 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers", comment: "Paper" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", comment: "Slug"
14
+ t.varchar "title1", limit: 300, comment: "Title 1"
15
+ t.varchar "title2", limit: 300, comment: "Title 2"
16
+
17
+ t.index "slug", name: "index_papers_on_slug", unique: true
18
+ end
19
+
20
+ create_table "paper_authors", comment: "Paper Author Relation" do |t|
21
+ t.int "id", primary_key: true, extra: "auto_increment"
22
+ t.int "paper_id", comment: "Paper id"
23
+ t.int "author_id", comment: "Paper author id"
24
+
25
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
26
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
27
+ end
@@ -0,0 +1,41 @@
1
+ DROP TABLE IF EXISTS paper_authors;
2
+ DROP TABLE IF EXISTS papers;
3
+ DROP TABLE IF EXISTS authors;
4
+
5
+ CREATE TABLE papers (
6
+ id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
7
+ slug varchar(255) NOT NULL,
8
+ title1 varchar(300) NOT NULL,
9
+ title2 varchar(300) NOT NULL,
10
+ description text,
11
+ edition_number integer NOT NULL DEFAULT 0,
12
+ published_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
13
+ );
14
+ CREATE UNIQUE INDEX index_papers_on_slug ON papers (slug);
15
+ COMMENT ON TABLE papers IS 'Paper';
16
+ COMMENT ON COLUMN papers.slug IS 'Slug';
17
+ COMMENT ON COLUMN papers.title1 IS 'Title 1';
18
+ COMMENT ON COLUMN papers.title2 IS 'Title 2';
19
+ COMMENT ON COLUMN papers.description IS 'Description';
20
+ COMMENT ON COLUMN papers.edition_number IS 'Edition number';
21
+ COMMENT ON COLUMN papers.published_at IS 'Published at';
22
+
23
+ CREATE TABLE authors (
24
+ id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
25
+ name varchar(110) NOT NULL,
26
+ age integer NOT NULL,
27
+ created_at timestamp,
28
+ updated_at timestamp
29
+ );
30
+ CREATE INDEX index_authors_on_created_at ON authors (created_at);
31
+
32
+ CREATE TABLE paper_authors (
33
+ id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
34
+ paper_id integer NOT NULL,
35
+ author_id integer NOT NULL,
36
+ CONSTRAINT paper_authors_author_id_fk FOREIGN KEY (author_id) REFERENCES authors (id),
37
+ CONSTRAINT paper_authors_paper_id_fk FOREIGN KEY (paper_id) REFERENCES papers (id)
38
+ );
39
+ COMMENT ON TABLE paper_authors IS 'Paper Author Relation';
40
+ COMMENT ON COLUMN paper_authors.paper_id IS 'Paper id';
41
+ COMMENT ON COLUMN paper_authors.author_id IS 'Paper author id';
@@ -0,0 +1,29 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+ t.text "description", null: true
17
+ t.varchar "subtitle", null: true
18
+
19
+ t.index "slug", name: "index_papers_on_slug", unique: true
20
+ end
21
+
22
+ create_table "paper_authors" do |t|
23
+ t.int "id", primary_key: true, extra: "auto_increment"
24
+ t.int "paper_id"
25
+ t.int "author_id"
26
+
27
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
28
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
29
+ end
@@ -0,0 +1,32 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+ t.text "description", null: true
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id"
24
+ t.int "author_id"
25
+
26
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
27
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
28
+ end
29
+
30
+ create_table "dummies" do |t|
31
+ t.int "id", primary_key: true, extra: "auto_increment"
32
+ end
@@ -0,0 +1,28 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 200
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+ t.text "description", null: true
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id"
24
+ t.int "author_id"
25
+
26
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
27
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
28
+ end
@@ -0,0 +1,25 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+ t.text "description", null: true
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
20
+
21
+ create_table "paper_authors" do |t|
22
+ t.int "id", primary_key: true, extra: "auto_increment"
23
+ t.int "paper_id"
24
+ t.int "author_id"
25
+ end
@@ -0,0 +1,19 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+ t.text "description", null: true
17
+
18
+ t.index "slug", name: "index_papers_on_slug", unique: true
19
+ end
@@ -0,0 +1,27 @@
1
+ create_table "authors" do |t|
2
+ t.int "id", primary_key: true, extra: "auto_increment"
3
+ t.varchar "name", limit: 110
4
+ t.int "age"
5
+ t.datetime "created_at", null: true
6
+ t.datetime "updated_at", null: true
7
+
8
+ t.index "created_at", name: "index_authors_on_created_at"
9
+ end
10
+
11
+ create_table "papers" do |t|
12
+ t.int "id", primary_key: true, extra: "auto_increment"
13
+ t.varchar "slug", limit: 255
14
+ t.varchar "title1", limit: 300
15
+ t.varchar "title2", limit: 300
16
+
17
+ t.index "slug", name: "index_papers_on_slug", unique: true
18
+ end
19
+
20
+ create_table "paper_authors" do |t|
21
+ t.int "id", primary_key: true, extra: "auto_increment"
22
+ t.int "paper_id"
23
+ t.int "author_id"
24
+
25
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
26
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
27
+ end