knjrbfw 0.0.45 → 0.0.46
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.
- data/VERSION +1 -1
- data/knjrbfw.gemspec +1 -1
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +8 -2
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +4 -1
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +14 -2
- data/lib/knj/knjdb/dump.rb +1 -0
- data/lib/knj/process.rb +1 -1
- data/spec/db_spec.rb +30 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.46
|
data/knjrbfw.gemspec
CHANGED
@@ -130,8 +130,14 @@ class KnjDB_mysql::Tables::Table
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def drop
|
133
|
-
|
134
|
-
@db.query(
|
133
|
+
raise "Cant drop native table: '#{self.name}'." if self.native?
|
134
|
+
@db.query("DROP TABLE `#{self.name}`")
|
135
|
+
end
|
136
|
+
|
137
|
+
#Returns true if the table is safe to drop.
|
138
|
+
def native?
|
139
|
+
return true if @db.q("SELECT DATABASE() AS db").fetch[:db] == "mysql"
|
140
|
+
return false
|
135
141
|
end
|
136
142
|
|
137
143
|
def optimize
|
@@ -85,6 +85,9 @@ class KnjDB_sqlite3::Columns::Column
|
|
85
85
|
elsif match = @args[:data][:type].match(/^(.+)\((\d+)\)$/)
|
86
86
|
@maxlength = match[2]
|
87
87
|
type = match[1].to_sym
|
88
|
+
elsif @args[:data].key?(:type) and @args[:data][:type].to_s == ""
|
89
|
+
#A type can actually be empty in SQLite... Wtf?
|
90
|
+
return @args[:data][:type]
|
88
91
|
end
|
89
92
|
|
90
93
|
if type == :integer
|
@@ -93,7 +96,7 @@ class KnjDB_sqlite3::Columns::Column
|
|
93
96
|
@type = type
|
94
97
|
end
|
95
98
|
|
96
|
-
raise "Still not type?" if @type.to_s.strip.length <= 0
|
99
|
+
raise "Still not type? (#{@args[:data]})" if @type.to_s.strip.length <= 0
|
97
100
|
end
|
98
101
|
|
99
102
|
return @type
|
@@ -113,15 +113,27 @@ class KnjDB_sqlite3::Tables::Table
|
|
113
113
|
return @data[:maxlength]
|
114
114
|
end
|
115
115
|
|
116
|
+
#Drops the table from the database.
|
116
117
|
def drop
|
117
|
-
|
118
|
-
@db.query(
|
118
|
+
raise "Cant drop native table: '#{self.name}'." if self.native?
|
119
|
+
@db.query("DROP TABLE `#{self.name}`")
|
120
|
+
end
|
121
|
+
|
122
|
+
#Returns true if the table is safe to drop.
|
123
|
+
def native?
|
124
|
+
return true if self.name.to_s == "sqlite_sequence"
|
125
|
+
return false
|
119
126
|
end
|
120
127
|
|
121
128
|
def optimize
|
122
129
|
raise "stub!"
|
123
130
|
end
|
124
131
|
|
132
|
+
def rename(newname)
|
133
|
+
self.clone(newname)
|
134
|
+
self.drop
|
135
|
+
end
|
136
|
+
|
125
137
|
def truncate
|
126
138
|
@db.query("DELETE FROM `#{self.name}` WHERE 1=1")
|
127
139
|
return nil
|
data/lib/knj/knjdb/dump.rb
CHANGED
data/lib/knj/process.rb
CHANGED
@@ -127,7 +127,7 @@ class Knj::Process
|
|
127
127
|
@on_rec.call(result_obj)
|
128
128
|
rescue SystemExit, Interrupt => e
|
129
129
|
raise e
|
130
|
-
rescue => e
|
130
|
+
rescue Exception => e
|
131
131
|
#Error was raised - try to forward it to the server.
|
132
132
|
result_obj.answer("type" => "process_error", "class" => e.class.name, "msg" => e.message, "backtrace" => e.backtrace)
|
133
133
|
end
|
data/spec/db_spec.rb
CHANGED
@@ -111,7 +111,7 @@ describe "Db" do
|
|
111
111
|
|
112
112
|
#Remove everything in the db.
|
113
113
|
db.tables.list do |table|
|
114
|
-
table.drop
|
114
|
+
table.drop unless table.native?
|
115
115
|
end
|
116
116
|
|
117
117
|
|
@@ -127,6 +127,35 @@ describe "Db" do
|
|
127
127
|
raise "Not same amount of tables: #{tables_count}, #{db.tables.list.length}" if tables_count != db.tables.list.length
|
128
128
|
|
129
129
|
|
130
|
+
|
131
|
+
#Test revision table renaming.
|
132
|
+
Knj::Db::Revision.new.init_db("db" => db, "schema" => {
|
133
|
+
"tables" => {
|
134
|
+
"new_test_table" => {
|
135
|
+
"renames" => ["test_table"]
|
136
|
+
}
|
137
|
+
}
|
138
|
+
})
|
139
|
+
tables = db.tables.list
|
140
|
+
raise "Didnt expect table 'test_table' to exist but it did." if tables.key?("test_table")
|
141
|
+
raise "Expected 'new_test_table' to exist but it didnt." if !tables.key?("new_test_table")
|
142
|
+
|
143
|
+
|
144
|
+
#Test revision for column renaming.
|
145
|
+
Knj::Db::Revision.new.init_db("db" => db, "schema" => {
|
146
|
+
"tables" => {
|
147
|
+
"new_test_table" => {
|
148
|
+
"columns" => [
|
149
|
+
{"name" => "new_name", "type" => "varchar", "renames" => ["name"]}
|
150
|
+
]
|
151
|
+
}
|
152
|
+
}
|
153
|
+
})
|
154
|
+
columns = db.tables["new_test_table"].columns
|
155
|
+
raise "Didnt expect 'name' to exist but it did." if columns.key?("name")
|
156
|
+
raise "Expected 'new_name'-column to exist but it didnt." if !columns.key?("new_name")
|
157
|
+
|
158
|
+
|
130
159
|
#Delete test-database if everything went well.
|
131
160
|
File.unlink(db_path) if File.exists?(db_path)
|
132
161
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knjrbfw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.46
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -379,7 +379,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
379
379
|
requirements:
|
380
380
|
- - ">="
|
381
381
|
- !ruby/object:Gem::Version
|
382
|
-
hash: -
|
382
|
+
hash: -3622671606985967169
|
383
383
|
segments:
|
384
384
|
- 0
|
385
385
|
version: "0"
|