Trouble migrating down
kalafut opened this issue · 3 comments
Hi. I'm really new to crystal and clear, so this might be a very basic issue. My migration is working fine up, but not down. The .down
block is called, but my SQL in execute
isn't being run. Here is the class:
class UserMigration_1
include Clear::Migration
def change(direction)
puts "HERE 1"
direction.up do
execute(%(
CREATE TABLE IF NOT EXISTS "users" (
"id" serial primary key,
"login" text UNIQUE NOT NULL,
"password" bytea NOT NULL,
"email" text,
"userid" text NOT NULL,
"publickey" bytea,
"privatekey" bytea,
"minrating" integer NOT NULL DEFAULT 0,
"maxrating" integer NOT NULL DEFAULT 5
);
))
end
direction.down do
puts "HERE 2"
execute(%q(DROP TABLE "users";))
puts "HERE 3"
end
end
end
If I migrated up then down the output looks like:
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [2ms] SELECT * FROM __clear_metadatas WHERE ("metatype" = 'migration')
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : Migrations will be applied (in this order):
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [ UP ] 1 - UserMigration_1
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [507µs] BEGIN
I, [2020-01-18 11:49:47 -08:00 #19005] INFO -- : [Direction::Up] UserMigration_1
HERE 1
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [960µs]
CREATE TABLE IF NOT EXISTS "users" (
...
"maxrating" integer NOT NULL DEFAULT 5
);
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [1ms] INSERT INTO "__clear_metadatas" ("metatype", "value") VALUES ('migration', '1')
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [522µs] COMMIT
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : Migrations will be applied (in this order):
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [DOWN] 1 - UserMigration_1
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [501µs] BEGIN
I, [2020-01-18 11:49:47 -08:00 #19005] INFO -- : [Direction::Down] UserMigration_1
HERE 1
HERE 2
HERE 3
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [1ms] DELETE FROM __clear_metadatas WHERE ("metatype" = 'migration') AND ("value" = '1')
D, [2020-01-18 11:49:47 -08:00 #19005] DEBUG -- : [503µs] COMMIT
HERE 2 and HERE3 are being hit, but the execute does nothing. Any ideas?
Through a bit of debugging I've found that by placing my SQL in the second term like execute("", "DROP TABLE...")
it works. But that seems odd since it being "down" should be the point of being defined in the .down
block. I was going off of these docs: https://clear.gitbook.io/project/migrations/call-migration-script#example
Thanks.
Using Clear::SQL.execute
instead works fine. Maybe a docs typo?
Indeed, this issue has been fixed in #154 by @mamantoha
Sorry for the inconvenience!