/
execute_sql.cr
44 lines (38 loc) · 1.21 KB
/
execute_sql.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Marten
module DB
abstract class Migration
module Operation
class ExecuteSQL < Base
getter forward_sql
getter backward_sql
def initialize(@forward_sql : String, @backward_sql : String? = nil)
end
def describe : String
"Run raw SQL"
end
def mutate_db_backward(
app_label : String,
schema_editor : Management::SchemaEditor::Base,
from_state : Management::ProjectState,
to_state : Management::ProjectState
) : Nil
schema_editor.execute(@backward_sql.not_nil!) unless @backward_sql.nil?
end
def mutate_db_forward(
app_label : String,
schema_editor : Management::SchemaEditor::Base,
from_state : Management::ProjectState,
to_state : Management::ProjectState
) : Nil
schema_editor.execute(@forward_sql)
end
def mutate_state_forward(app_label : String, state : Management::ProjectState) : Nil
end
def serialize : String
ECR.render "#{__DIR__}/templates/execute_sql.ecr"
end
end
end
end
end
end