aboutsummaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-25 17:36:15 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-28 14:28:35 +0100
commit986cb536457e921dacf7ab5c7bc16ad4b2108781 (patch)
tree29a3541234dd413cbb133502b79d602c48d2c35d /app
parent73f7eabb6e10cff09a79105b6525e3c269e3cf08 (diff)
downloadwallabag-986cb536457e921dacf7ab5c7bc16ad4b2108781.tar.gz
wallabag-986cb536457e921dacf7ab5c7bc16ad4b2108781.tar.zst
wallabag-986cb536457e921dacf7ab5c7bc16ad4b2108781.zip
Removed my hasColumn and used the existing one in Doctrine
Diffstat (limited to 'app')
-rw-r--r--app/DoctrineMigrations/Version20160410190541.php36
1 files changed, 1 insertions, 35 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php
index 5de53d4b..c2360937 100644
--- a/app/DoctrineMigrations/Version20160410190541.php
+++ b/app/DoctrineMigrations/Version20160410190541.php
@@ -24,46 +24,12 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
24 return $this->container->getParameter('database_table_prefix').$tableName; 24 return $this->container->getParameter('database_table_prefix').$tableName;
25 } 25 }
26 26
27 private function hasColumn($tableName, $columnName)
28 {
29 switch ($this->connection->getDatabasePlatform()->getName()) {
30 case 'sqlite':
31 $rows = $this->connection->executeQuery('pragma table_info('.$tableName.')')->fetchAll();
32 foreach ($rows as $column) {
33 if (strcasecmp($column['name'], $columnName) === 0) {
34 return true;
35 }
36 }
37
38 return false;
39 case 'mysql':
40 $rows = $this->connection->executeQuery('SHOW COLUMNS FROM '.$tableName)->fetchAll();
41 foreach ($rows as $column) {
42 if (strcasecmp($column['Field'], $columnName) === 0) {
43 return true;
44 }
45 }
46
47 return false;
48 case 'postgresql':
49 $sql = sprintf("SELECT count(*)
50 FROM information_schema.columns
51 WHERE table_schema = 'public' AND table_name = '%s' AND column_name = '%s'",
52 $tableName,
53 $columnName
54 );
55 $result = $this->connection->executeQuery($sql)->fetch();
56
57 return $result['count'] > 0;
58 }
59 }
60
61 /** 27 /**
62 * @param Schema $schema 28 * @param Schema $schema
63 */ 29 */
64 public function up(Schema $schema) 30 public function up(Schema $schema)
65 { 31 {
66 $this->skipIf($this->hasColumn($this->getTable('entry'), 'uuid'), 'It seems that you already played this migration.'); 32 $this->skipIf($schema->getTable($this->getTable('entry'))->hasColumn('uuid'), 'It seems that you already played this migration.');
67 33
68 if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') { 34 if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') {
69 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL'); 35 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL');