baza 0.0.38 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -14
  3. data/lib/baza/database.rb +1 -1
  4. data/lib/baza/db.rb +5 -4
  5. data/lib/baza/driver/active_record/columns.rb +2 -2
  6. data/lib/baza/driver/active_record/commands.rb +2 -2
  7. data/lib/baza/driver/active_record/databases.rb +2 -2
  8. data/lib/baza/driver/active_record/foreign_keys.rb +13 -0
  9. data/lib/baza/driver/active_record/indexes.rb +2 -2
  10. data/lib/baza/driver/active_record/tables.rb +3 -3
  11. data/lib/baza/driver/active_record/users.rb +2 -2
  12. data/lib/baza/driver/active_record.rb +3 -1
  13. data/lib/baza/driver/mysql/columns.rb +1 -1
  14. data/lib/baza/driver/mysql/database.rb +11 -38
  15. data/lib/baza/driver/mysql/foreign_key.rb +2 -0
  16. data/lib/baza/driver/mysql/foreign_keys.rb +13 -0
  17. data/lib/baza/driver/mysql/sql/column.rb +3 -2
  18. data/lib/baza/driver/mysql/sql/create_table.rb +11 -0
  19. data/lib/baza/driver/mysql/table.rb +43 -4
  20. data/lib/baza/driver/mysql/tables.rb +22 -9
  21. data/lib/baza/driver/mysql2/foreign_keys.rb +2 -0
  22. data/lib/baza/driver/mysql2.rb +6 -5
  23. data/lib/baza/driver/mysql_java.rb +2 -2
  24. data/lib/baza/driver/pg/columns.rb +1 -1
  25. data/lib/baza/driver/pg/create_index_sql_creator.rb +2 -5
  26. data/lib/baza/driver/pg/database.rb +2 -2
  27. data/lib/baza/driver/pg/foreign_key.rb +2 -0
  28. data/lib/baza/driver/pg/foreign_keys.rb +13 -0
  29. data/lib/baza/driver/pg/result.rb +5 -1
  30. data/lib/baza/driver/pg/table.rb +43 -0
  31. data/lib/baza/driver/pg/tables.rb +20 -13
  32. data/lib/baza/driver/sqlite3/columns.rb +1 -1
  33. data/lib/baza/driver/sqlite3/foreign_key.rb +14 -0
  34. data/lib/baza/driver/sqlite3/foreign_keys.rb +11 -0
  35. data/lib/baza/driver/sqlite3/table.rb +41 -6
  36. data/lib/baza/driver/sqlite3/tables.rb +15 -14
  37. data/lib/baza/driver/sqlite3.rb +1 -1
  38. data/lib/baza/driver/sqlite3_java.rb +1 -1
  39. data/lib/baza/driver/sqlite3_rhodes.rb +1 -1
  40. data/lib/baza/dump.rb +3 -2
  41. data/lib/baza/foreign_key.rb +1 -1
  42. data/lib/baza/jdbc_driver.rb +1 -1
  43. data/lib/baza/mysql_base_driver.rb +1 -1
  44. data/lib/baza/query_buffer.rb +36 -6
  45. data/lib/baza/result_base.rb +2 -5
  46. data/lib/baza/tables.rb +1 -1
  47. metadata +26 -269
  48. data/.document +0 -5
  49. data/.github/dependabot.yml +0 -13
  50. data/.rspec +0 -1
  51. data/.rubocop.yml +0 -84
  52. data/.rubocop_todo.yml +0 -39
  53. data/.ruby-version +0 -1
  54. data/Gemfile +0 -32
  55. data/Gemfile.lock +0 -164
  56. data/VERSION +0 -1
  57. data/baza.gemspec +0 -264
  58. data/config/best_project_practice_rubocop.yml +0 -10
  59. data/config/best_project_practice_rubocop_todo.yml +0 -163
  60. data/peak_flow.yml +0 -31
  61. data/spec/active_record/models/user.rb +0 -3
  62. data/spec/baza/cloner_spec.rb +0 -10
  63. data/spec/baza/sql_queries/generic_insert_spec.rb +0 -26
  64. data/spec/baza/sql_queries/select_spec.rb +0 -38
  65. data/spec/drivers/active_record_mysql2_spec.rb +0 -22
  66. data/spec/drivers/active_record_mysql_spec.rb +0 -19
  67. data/spec/drivers/active_record_pg_spec.rb +0 -22
  68. data/spec/drivers/active_record_sqlite3_spec.rb +0 -18
  69. data/spec/drivers/mysql2_spec.rb +0 -19
  70. data/spec/drivers/mysql_spec.rb +0 -58
  71. data/spec/drivers/pg/columns_spec.rb +0 -45
  72. data/spec/drivers/pg/table_spec.rb +0 -20
  73. data/spec/drivers/pg_spec.rb +0 -20
  74. data/spec/drivers/sqlite3_spec.rb +0 -67
  75. data/spec/drivers/tiny_spec.rb +0 -27
  76. data/spec/info_active_record_example.rb +0 -35
  77. data/spec/info_active_record_mysql2_example.rb +0 -36
  78. data/spec/info_active_record_mysql2_peak_flow.rb +0 -36
  79. data/spec/info_active_record_mysql_example.rb +0 -37
  80. data/spec/info_active_record_mysql_peak_flow.rb +0 -37
  81. data/spec/info_active_record_pg_example.rb +0 -36
  82. data/spec/info_active_record_pg_peak_flow.rb +0 -36
  83. data/spec/info_active_record_sqlite3.rb +0 -29
  84. data/spec/info_mysql2_example.rb +0 -21
  85. data/spec/info_mysql2_peak_flow.rb +0 -21
  86. data/spec/info_mysql_example.rb +0 -21
  87. data/spec/info_mysql_peak_flow.rb +0 -21
  88. data/spec/info_pg_example.rb +0 -22
  89. data/spec/info_pg_peak_flow.rb +0 -22
  90. data/spec/info_sqlite3.rb +0 -19
  91. data/spec/spec_helper.rb +0 -18
  92. data/spec/support/driver_active_record_collection.rb +0 -62
  93. data/spec/support/driver_collection.rb +0 -396
  94. data/spec/support/driver_columns_collection.rb +0 -64
  95. data/spec/support/driver_databases_collection.rb +0 -48
  96. data/spec/support/driver_foreign_keys_collection.rb +0 -54
  97. data/spec/support/driver_importer_collection.rb +0 -38
  98. data/spec/support/driver_indexes_collection.rb +0 -66
  99. data/spec/support/driver_tables_collection.rb +0 -116
  100. data/spec/support/driver_users_collection.rb +0 -53
@@ -1,48 +0,0 @@
1
- shared_examples_for "a baza databases driver" do
2
- let(:driver) { constant.new }
3
- let(:driver2) { constant.new }
4
- let(:db) { driver.db }
5
- let(:db2) { driver2.db }
6
- let(:test_database) do
7
- db.databases.create(name: "baza-test-create", if_not_exists: true)
8
- db.databases["baza-test-create"]
9
- end
10
-
11
- it "renames database" do
12
- begin
13
- db.databases["renamed-db"].drop
14
- # rubocop:disable Lint/HandleExceptions
15
- rescue Baza::Errors::DatabaseNotFound
16
- # rubocop:enable Lint/HandleExceptions
17
- # Ignore - it shouldn't exist
18
- end
19
-
20
- test_database.name = "renamed-db"
21
- test_database.save!
22
-
23
- expect(test_database.name).to eq "renamed-db"
24
- end
25
-
26
- it "drops databases" do
27
- test_database.drop
28
- expect { db.databases["baza-test-create"] }.to raise_error(Baza::Errors::DatabaseNotFound)
29
- end
30
-
31
- it "creates tables" do
32
- test_database.table("test").drop if test_database.table_exists?("test")
33
-
34
- test_database.create_table(
35
- "test",
36
- columns: [
37
- {name: :id, type: :int, autoincr: true, primarykey: true},
38
- {name: :name, type: :varchar}
39
- ]
40
- )
41
-
42
- tables = test_database.tables.map(&:name).to_a
43
- expect(tables).to eq ["test"]
44
-
45
- table = test_database.table("test")
46
- expect(table.name).to eq "test"
47
- end
48
- end
@@ -1,54 +0,0 @@
1
- shared_examples_for "a baza foreign keys driver" do
2
- let(:driver) { constant.new }
3
- let(:db) { driver.db }
4
- let(:posts_table) do
5
- db.tables.create(
6
- "posts",
7
- columns: [
8
- {name: "id", type: :int, autoincr: true, primarykey: true},
9
- {name: "user_id", type: :int},
10
- {name: "text", type: :varchar}
11
- ]
12
- )
13
- db.tables[:posts]
14
- end
15
- let(:users_table) do
16
- db.tables.create(
17
- "users",
18
- columns: [
19
- {name: "id", type: :int, autoincr: true, primarykey: true},
20
- {name: "email", type: :varchar}
21
- ]
22
- )
23
- db.tables[:users]
24
- end
25
- let(:users_id_column) { users_table.column("id") }
26
- let(:user_id_foreign_key) do
27
- posts_table.column("user_id").create_foreign_key(
28
- column: users_id_column,
29
- name: "test_column_key"
30
- )
31
- posts_table.foreign_key("test_column_key")
32
- end
33
-
34
- before do
35
- driver.before
36
- end
37
-
38
- after do
39
- driver.after
40
- end
41
-
42
- it "creates foreign keys" do
43
- user_id_foreign_key
44
-
45
- expect(posts_table.foreign_keys.length).to eq 1
46
- expect(posts_table.foreign_key("test_column_key").name).to eq "test_column_key"
47
- end
48
-
49
- it "destroys foreign keys" do
50
- user_id_foreign_key.drop
51
-
52
- expect { posts_table.foreign_key("test_column_key") }.to raise_error(Baza::Errors::ForeignKeyNotFound)
53
- end
54
- end
@@ -1,38 +0,0 @@
1
- shared_examples_for "a baza importer driver" do
2
- let(:driver) { constant.new(debug: false) }
3
- let(:db) { driver.db }
4
- let(:test_table) do
5
- db.tables.create(
6
- "test",
7
- columns: [
8
- {name: "id", type: :int, autoincr: true, primarykey: true},
9
- {name: "text", type: :varchar}
10
- ]
11
- )
12
- db.tables[:test]
13
- end
14
-
15
- before do
16
- driver.before
17
- end
18
-
19
- after do
20
- driver.after
21
- end
22
-
23
- it "imports sql" do
24
- test_table
25
-
26
- io = StringIO.new
27
- dumper = Baza::Dump.new(db: db)
28
- dumper.dump(io)
29
- io.rewind
30
-
31
- test_table.drop
32
-
33
- importer = Baza::Commands::Importer.new(db: db, io: io)
34
- importer.execute
35
-
36
- expect(db.tables[:test].name).to eq "test"
37
- end
38
- end
@@ -1,66 +0,0 @@
1
- shared_examples_for "a baza indexes driver" do
2
- let(:driver) { constant.new }
3
- let(:db) { driver.db }
4
- let(:test_table) do
5
- db.tables.create(
6
- "test",
7
- columns: [
8
- {name: "id", type: :int, autoincr: true, primarykey: true},
9
- {name: "text", type: :varchar},
10
- {name: "email", type: :varchar}
11
- ],
12
- indexes: [
13
- :text,
14
- {name: :email, unique: true, columns: [:email]},
15
- {name: :two_columns, columns: [:text, :email]}
16
- ]
17
- )
18
- db.tables[:test]
19
- end
20
-
21
- before do
22
- driver.before
23
- end
24
-
25
- after do
26
- driver.after
27
- end
28
-
29
- it "renames indexes for renamed tables" do
30
- # Load up columns to make them set table-name.
31
- test_table.indexes.each do |name, index|
32
- end
33
-
34
- test_table.create_indexes([{name: "index_on_text", columns: [:text]}])
35
- test_table.rename("test2")
36
- test_table.index("index_on_text").rename("index_on_text2")
37
-
38
- table = db.tables[:test2]
39
- index = table.index(:index_on_text2)
40
- expect(index.table.name).to eq "test2"
41
- end
42
-
43
- it "raises an error when an index isn't found" do
44
- expect do
45
- test_table.index("index_that_doesnt_exist")
46
- end.to raise_error(Baza::Errors::IndexNotFound)
47
- end
48
-
49
- describe Baza::Index do
50
- describe "#unique?" do
51
- it "returns true when it is unique" do
52
- expect(test_table.index("email").unique?).to eq true
53
- end
54
-
55
- it "returns false when it isn't unique" do
56
- expect(test_table.index("text").unique?).to eq false
57
- end
58
- end
59
-
60
- describe "#columns" do
61
- it "returns the correct columns" do
62
- expect(test_table.index("two_columns").columns).to eq %w(text email)
63
- end
64
- end
65
- end
66
- end
@@ -1,116 +0,0 @@
1
- shared_examples_for "a baza tables driver" do
2
- let(:driver) { constant.new }
3
- let(:driver2) { constant.new }
4
- let(:db) { driver.db }
5
- let(:db2) { driver2.db }
6
- let(:test_table) do
7
- db.tables.create(
8
- "test",
9
- columns: [
10
- {name: "id", type: :int, autoincr: true, primarykey: true},
11
- {name: "text", type: :varchar}
12
- ]
13
- )
14
- db.tables[:test]
15
- end
16
-
17
- before do
18
- driver.before
19
- end
20
-
21
- after do
22
- driver.after
23
- end
24
-
25
- it "creates tables" do
26
- expect(test_table.name).to eq "test"
27
- expect(db.tables[:test].name).to eq "test"
28
- end
29
-
30
- describe "#exists?" do
31
- it "returns true for tables that exists" do
32
- test_table
33
- expect(db.tables.exists?("test")).to eq true
34
- end
35
-
36
- it "returns false for tables that doesnt exist" do
37
- expect(db.tables.exists?("testtest")).to eq false
38
- end
39
- end
40
-
41
- it "#list" do
42
- test_table
43
- expect(db.tables.list).to include test_table
44
- end
45
-
46
- it "#optimize" do
47
- test_table.optimize
48
- # FIXME: How to validate?
49
- end
50
-
51
- it "#rows_count" do
52
- expect(test_table.rows_count).to eq 0
53
- test_table.insert(text: "Test")
54
- expect(test_table.rows_count).to eq 1
55
- end
56
-
57
- it "#native?" do
58
- expect(test_table.native?).to eq false
59
- end
60
-
61
- it "#row" do
62
- expect { test_table.row(500) }.to raise_error(Baza::Errors::RowNotFound)
63
- test_table.insert(id: 1, text: "Test")
64
- expect(test_table.row(1)[:text]).to eq "Test"
65
- end
66
-
67
- it "#truncate" do
68
- test_table
69
-
70
- db.insert(:test, text: "test")
71
- expect(db.select(:test).fetch.fetch(:id).to_i).to eq 1
72
- expect(test_table.rows_count).to eq 1
73
-
74
- # Throw out invalid encoding because it will make dumping fail.
75
- db.tables[:test].truncate
76
- expect(test_table.rows_count).to eq 0
77
-
78
- db.insert(:test, text: "test")
79
- expect(db.select(:test).fetch.fetch(:id).to_i).to eq 1
80
- end
81
-
82
- it "#clone" do
83
- test_table
84
- test_table.create_indexes([{name: "index_on_text", columns: ["text"]}])
85
-
86
- expect(test_table.indexes.length).to eq 1
87
-
88
- test_table.insert(text: "test1")
89
- test_table.insert(text: "test2")
90
-
91
- test_table.clone("test2")
92
- test_table2 = db.tables[:test2]
93
-
94
- expect(test_table2.columns.length).to eq test_table.columns.length
95
- expect(test_table2.indexes.length).to eq test_table.indexes.length
96
- expect(test_table2.rows_count).to eq test_table.rows_count
97
- expect(test_table2.rows_count).to eq 2
98
- end
99
-
100
- describe "#reload" do
101
- it "reloads the data on the table" do
102
- test_table.reload
103
- expect(test_table.name).to eq "test"
104
-
105
- test_table.drop
106
- expect { test_table.reload }.to raise_error(Baza::Errors::TableNotFound)
107
- end
108
- end
109
-
110
- describe "Baza::Table#rows_count" do
111
- it "returns the number of rows in the table" do
112
- 3.times { |n| test_table.insert(text: "Test #{n}") }
113
- expect(test_table.rows_count).to eq 3
114
- end
115
- end
116
- end
@@ -1,53 +0,0 @@
1
- require "spec_helper"
2
-
3
- shared_examples_for "a baza users driver" do
4
- let(:driver) { constant.new }
5
- let(:db) { driver.db }
6
- let(:test_user_name) { "baza-test-create" }
7
- let(:user) { db.users.create(name: test_user_name, host: "localhost", password: "mypassword") }
8
-
9
- before do
10
- # Drop any existing user with the test user name
11
- begin
12
- db.users.find_by_name(test_user_name).drop
13
- rescue Baza::Errors::UserNotFound # rubocop:disable Lint/HandleExceptions
14
- end
15
- end
16
-
17
- it "Users#list" do
18
- root_found = false
19
- db.users.list do |user|
20
- if user.name == "root"
21
- root_found = true
22
- break
23
- end
24
- end
25
-
26
- expect(root_found).to eq true
27
- end
28
-
29
- it "Users#find_by_name" do
30
- root_user = db.users.find_by_name("root")
31
- expect(root_user.name).to eq "root"
32
- end
33
-
34
- it "Users#create" do
35
- my_user = db.users.create(name: test_user_name, host: "localhost", password: "mypassword")
36
-
37
- expect(my_user.name).to eq test_user_name
38
- expect(my_user.host).to eq "localhost"
39
- end
40
-
41
- it "User#drop" do
42
- user.drop
43
- expect { db.users.find_by_name(test_user_name) }.to raise_error(Baza::Errors::UserNotFound)
44
- end
45
-
46
- it "User#name" do
47
- expect(user.name).to eq test_user_name
48
- end
49
-
50
- it "User#host" do
51
- expect(user.host).to eq "localhost"
52
- end
53
- end