@@ -26,8 +26,8 @@ class PgSqlDriver extends BaseDriver implements IDriver
26
26
/** @var string */
27
27
protected $ schema ;
28
28
29
- /** @var string */
30
- protected $ schemaStr ;
29
+ /** @var NULL| string */
30
+ protected $ schemaQuoted ;
31
31
32
32
33
33
/**
@@ -38,20 +38,21 @@ class PgSqlDriver extends BaseDriver implements IDriver
38
38
public function __construct (IDbal $ dbal , $ tableName = 'migrations ' , $ schema = 'public ' )
39
39
{
40
40
parent ::__construct ($ dbal , $ tableName );
41
- $ this ->schema = $ dbal ->escapeIdentifier ($ schema );
42
- $ this ->schemaStr = $ dbal ->escapeString ($ schema );
41
+ $ this ->schema = $ schema ;
43
42
}
44
43
45
44
46
45
public function setupConnection ()
47
46
{
47
+ parent ::setupConnection ();
48
+ $ this ->schemaQuoted = $ this ->dbal ->escapeIdentifier ($ this ->schema );
48
49
}
49
50
50
51
51
52
public function emptyDatabase ()
52
53
{
53
- $ this ->dbal ->exec ("DROP SCHEMA IF EXISTS {$ this ->schema } CASCADE " );
54
- $ this ->dbal ->exec ("CREATE SCHEMA {$ this ->schema }" );
54
+ $ this ->dbal ->exec ("DROP SCHEMA IF EXISTS {$ this ->schemaQuoted } CASCADE " );
55
+ $ this ->dbal ->exec ("CREATE SCHEMA {$ this ->schemaQuoted }" );
55
56
}
56
57
57
58
@@ -103,14 +104,14 @@ public function createTable()
103
104
104
105
public function dropTable ()
105
106
{
106
- $ this ->dbal ->exec ("DROP TABLE {$ this ->schema }. {$ this ->tableName }" );
107
+ $ this ->dbal ->exec ("DROP TABLE {$ this ->schemaQuoted }. {$ this ->tableNameQuoted }" );
107
108
}
108
109
109
110
110
111
public function insertMigration (Migration $ migration )
111
112
{
112
113
$ rows = $ this ->dbal ->query ("
113
- INSERT INTO {$ this ->schema }. {$ this ->tableName }" . '
114
+ INSERT INTO {$ this ->schemaQuoted }. {$ this ->tableNameQuoted }" . '
114
115
("group", "file", "checksum", "executed", "ready") VALUES ( ' .
115
116
$ this ->dbal ->escapeString ($ migration ->group ) . ", " .
116
117
$ this ->dbal ->escapeString ($ migration ->filename ) . ", " .
@@ -128,7 +129,7 @@ public function insertMigration(Migration $migration)
128
129
public function markMigrationAsReady (Migration $ migration )
129
130
{
130
131
$ this ->dbal ->exec ("
131
- UPDATE {$ this ->schema }. {$ this ->tableName }" . '
132
+ UPDATE {$ this ->schemaQuoted }. {$ this ->tableNameQuoted }" . '
132
133
SET "ready" = TRUE
133
134
WHERE "id" = ' . $ this ->dbal ->escapeInt ($ migration ->id )
134
135
);
@@ -138,7 +139,7 @@ public function markMigrationAsReady(Migration $migration)
138
139
public function getAllMigrations ()
139
140
{
140
141
$ migrations = array ();
141
- $ result = $ this ->dbal ->query ("SELECT * FROM {$ this ->schema }. {$ this ->tableName } ORDER BY \"executed \"" );
142
+ $ result = $ this ->dbal ->query ("SELECT * FROM {$ this ->schemaQuoted }. {$ this ->tableNameQuoted } ORDER BY \"executed \"" );
142
143
foreach ($ result as $ row ) {
143
144
$ migration = new Migration ;
144
145
$ migration ->id = (int ) $ row ['id ' ];
@@ -158,7 +159,7 @@ public function getAllMigrations()
158
159
public function getInitTableSource ()
159
160
{
160
161
return preg_replace ('#^\t{3}#m ' , '' , trim ("
161
- CREATE TABLE IF NOT EXISTS {$ this ->schema }. {$ this ->tableName } ( " . '
162
+ CREATE TABLE IF NOT EXISTS {$ this ->schemaQuoted }. {$ this ->tableNameQuoted } ( " . '
162
163
"id" serial4 NOT NULL,
163
164
"group" varchar(100) NOT NULL,
164
165
"file" varchar(100) NOT NULL,
@@ -176,7 +177,7 @@ public function getInitMigrationsSource(array $files)
176
177
{
177
178
$ out = '' ;
178
179
foreach ($ files as $ file ) {
179
- $ out .= "INSERT INTO {$ this ->schema }. {$ this ->tableName } " ;
180
+ $ out .= "INSERT INTO {$ this ->schemaQuoted }. {$ this ->tableNameQuoted } " ;
180
181
$ out .= '("group", "file", "checksum", "executed", "ready") VALUES ( ' .
181
182
$ this ->dbal ->escapeString ($ file ->group ->name ) . ", " .
182
183
$ this ->dbal ->escapeString ($ file ->name ) . ", " .
0 commit comments