Skip to content

Commit dbc285a

Browse files
committed
Drop PostGIS extension if it exists
1 parent a9dc605 commit dbc285a

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

src/Schema/Blueprint.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,15 @@ public function disablePostgis()
148148
return $this->addCommand('disablePostgis');
149149
}
150150

151+
/**
152+
* Disable postgis on this database.
153+
* WIll drop the extension in the database if it exists.
154+
*
155+
* @return \Illuminate\Support\Fluent
156+
*/
157+
public function disablePostgisIfExists()
158+
{
159+
return $this->addCommand('disablePostgisIfExists');
160+
}
161+
151162
}

src/Schema/Builder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ public function disablePostgis()
5454
$this->grammar->compileDisablePostgis()
5555
);
5656
}
57+
58+
/**
59+
* Disable postgis on this database.
60+
* WIll drop the extension in the database if it exists.
61+
*
62+
* @return bool
63+
*/
64+
public function disablePostgisIfExists()
65+
{
66+
return $this->connection->statement(
67+
$this->grammar->compileDisablePostgisIfExists()
68+
);
69+
}
5770
}

src/Schema/Grammars/PostgisGrammar.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ public function compileDisablePostgis()
153153
return 'DROP EXTENSION postgis';
154154
}
155155

156+
/**
157+
* Adds a statement to drop the postgis extension, if it exists
158+
*
159+
* @return string
160+
*/
161+
public function compileDisablePostgisIfExists()
162+
{
163+
return 'DROP EXTENSION IF EXISTS postgis';
164+
}
165+
156166
/**
157167
* Adds a statement to add a geometry column
158168
*

tests/Schema/BlueprintTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ public function testDisablePostgis()
107107

108108
$this->blueprint->disablePostgis();
109109
}
110+
111+
public function testDisablePostgisIfExists()
112+
{
113+
$this->blueprint
114+
->shouldReceive('addCommand')
115+
->with('disablePostgis', []);
116+
117+
$this->blueprint->disablePostgisIfExists();
118+
}
110119
}

tests/Schema/Grammars/PostgisGrammarTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ public function testDisablePostgis()
294294
$this->assertStringContainsString('DROP EXTENSION postgis', $statements[0]);
295295
}
296296

297+
public function testDisablePostgisIfExists()
298+
{
299+
$blueprint = new Blueprint('test');
300+
$blueprint->disablePostgisIfExists();
301+
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
302+
303+
$this->assertCount(1, $statements);;
304+
$this->assertStringContainsString('DROP EXTENSION IF EXISTS postgis', $statements[0]);
305+
}
306+
297307
/**
298308
* @return Connection
299309
*/

0 commit comments

Comments
 (0)