-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding in extension support. * Update src/avram/migrator/alter_extension_statement.cr Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com> Co-authored-by: Paul Smith <paulcsmith@users.noreply.github.com>
- Loading branch information
1 parent
27edded
commit c160ddd
Showing
7 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "../spec_helper" | ||
|
||
describe Avram::Migrator::AlterExtensionStatement do | ||
it "builds the proper SQL to update an extension" do | ||
statement = Avram::Migrator::AlterExtensionStatement.new("uuid-ossp") | ||
statement.build.should eq %{ALTER EXTENSION "uuid-ossp" UPDATE;} | ||
end | ||
|
||
it "updates to a specific version" do | ||
statement = Avram::Migrator::AlterExtensionStatement.new("hstore", to: "2.0") | ||
statement.build.should eq %{ALTER EXTENSION "hstore" UPDATE TO '2.0';} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "../spec_helper" | ||
|
||
describe Avram::Migrator::CreateExtensionStatement do | ||
it "builds the proper SQL for creating an extension" do | ||
statement = Avram::Migrator::CreateExtensionStatement.new("uuid-ossp") | ||
statement.build.should eq %{CREATE EXTENSION IF NOT EXISTS "uuid-ossp";} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "../spec_helper" | ||
|
||
describe Avram::Migrator::DropExtensionStatement do | ||
it "builds the proper SQL for dropping an extension" do | ||
statement = Avram::Migrator::DropExtensionStatement.new("uuid-ossp") | ||
statement.build.should eq %{DROP EXTENSION IF EXISTS "uuid-ossp" CASCADE;} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Avram::Migrator::AlterExtensionStatement | ||
def initialize(@name : String, @to : String? = nil) | ||
end | ||
|
||
def build | ||
String.build do |sql| | ||
sql << %{ALTER EXTENSION "#{@name}" UPDATE} | ||
sql << to_version if @to | ||
sql << ";" | ||
end | ||
end | ||
|
||
def to_version | ||
" TO '#{@to}'" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Avram::Migrator::CreateExtensionStatement | ||
def initialize(@name : String) | ||
end | ||
|
||
def build | ||
<<-SQL | ||
CREATE EXTENSION IF NOT EXISTS "#{@name}"; | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Avram::Migrator::DropExtensionStatement | ||
def initialize(@name : String) | ||
end | ||
|
||
def build | ||
<<-SQL | ||
DROP EXTENSION IF EXISTS "#{@name}" CASCADE; | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters