diff options
author | adev <adev2000@gmail.com> | 2017-11-04 21:23:18 +0100 |
---|---|---|
committer | adev <adev2000@gmail.com> | 2017-11-21 21:35:17 +0100 |
commit | 2680b0bc8c9044b19b80a596f0005a1051b4ee54 (patch) | |
tree | d5e4fc059c633b5a2324d58e311f3bbd982f9edc | |
parent | 2054740fdbae49a3900d84e0b4d2a604c5b099a5 (diff) | |
download | wallabag-2680b0bc8c9044b19b80a596f0005a1051b4ee54.tar.gz wallabag-2680b0bc8c9044b19b80a596f0005a1051b4ee54.tar.zst wallabag-2680b0bc8c9044b19b80a596f0005a1051b4ee54.zip |
Fix installation command
4 files changed, 43 insertions, 31 deletions
diff --git a/app/DoctrineMigrations/Version20160812120952.php b/app/DoctrineMigrations/Version20160812120952.php index 677f30c3..d28f3a71 100644 --- a/app/DoctrineMigrations/Version20160812120952.php +++ b/app/DoctrineMigrations/Version20160812120952.php | |||
@@ -30,7 +30,20 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI | |||
30 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); | 30 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); |
31 | $this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.'); | 31 | $this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.'); |
32 | 32 | ||
33 | $clientsTable->addColumn('name', 'blob'); | 33 | if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) { |
34 | // Can't use $clientsTable->addColumn('name', 'blob'); | ||
35 | // because of the error: | ||
36 | // SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL | ||
37 | $databaseTablePrefix = $this->container->getParameter('database_table_prefix'); | ||
38 | $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); | ||
39 | $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); | ||
40 | $this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, random_id VARCHAR(255) NOT NULL COLLATE BINARY, secret VARCHAR(255) NOT NULL COLLATE BINARY, redirect_uris CLOB NOT NULL, allowed_grant_types CLOB NOT NULL, name CLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_635D765EA76ED395 FOREIGN KEY (user_id) REFERENCES "' . $databaseTablePrefix . 'user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); | ||
41 | $this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients'); | ||
42 | $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); | ||
43 | $this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $databaseTablePrefix . 'oauth2_clients (user_id)'); | ||
44 | } else { | ||
45 | $clientsTable->addColumn('name', 'blob'); | ||
46 | } | ||
34 | } | 47 | } |
35 | 48 | ||
36 | /** | 49 | /** |
@@ -39,7 +52,18 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI | |||
39 | public function down(Schema $schema) | 52 | public function down(Schema $schema) |
40 | { | 53 | { |
41 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); | 54 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); |
42 | $clientsTable->dropColumn('name'); | 55 | |
56 | if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) { | ||
57 | $databaseTablePrefix = $this->container->getParameter('database_table_prefix'); | ||
58 | $this->addSql('DROP INDEX IDX_635D765EA76ED395'); | ||
59 | $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); | ||
60 | $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); | ||
61 | $this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, random_id VARCHAR(255) NOT NULL, secret VARCHAR(255) NOT NULL, redirect_uris CLOB NOT NULL COLLATE BINARY, allowed_grant_types CLOB NOT NULL COLLATE BINARY, PRIMARY KEY(id))'); | ||
62 | $this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients'); | ||
63 | $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); | ||
64 | } else { | ||
65 | $clientsTable->dropColumn('name'); | ||
66 | } | ||
43 | } | 67 | } |
44 | 68 | ||
45 | private function getTable($tableName) | 69 | private function getTable($tableName) |
diff --git a/app/DoctrineMigrations/Version20170824113337.php b/app/DoctrineMigrations/Version20170824113337.php index 7393d683..e54a9bcf 100644 --- a/app/DoctrineMigrations/Version20170824113337.php +++ b/app/DoctrineMigrations/Version20170824113337.php | |||
@@ -41,7 +41,12 @@ class Version20170824113337 extends AbstractMigration implements ContainerAwareI | |||
41 | $entryTable = $schema->getTable($this->getTable('entry')); | 41 | $entryTable = $schema->getTable($this->getTable('entry')); |
42 | $this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum'); | 42 | $this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum'); |
43 | 43 | ||
44 | $this->connection->executeQuery('UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = true'); | 44 | $this->connection->executeQuery( |
45 | 'UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = :is_starred', | ||
46 | [ | ||
47 | 'is_starred' => true, | ||
48 | ] | ||
49 | ); | ||
45 | } | 50 | } |
46 | 51 | ||
47 | /** | 52 | /** |
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 877dbfa2..dec2bf9c 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -61,7 +61,6 @@ class InstallCommand extends ContainerAwareCommand | |||
61 | ->setupDatabase() | 61 | ->setupDatabase() |
62 | ->setupAdmin() | 62 | ->setupAdmin() |
63 | ->setupConfig() | 63 | ->setupConfig() |
64 | ->runMigrations() | ||
65 | ; | 64 | ; |
66 | 65 | ||
67 | $this->io->success('Wallabag has been successfully installed.'); | 66 | $this->io->success('Wallabag has been successfully installed.'); |
@@ -70,7 +69,7 @@ class InstallCommand extends ContainerAwareCommand | |||
70 | 69 | ||
71 | protected function checkRequirements() | 70 | protected function checkRequirements() |
72 | { | 71 | { |
73 | $this->io->section('Step 1 of 5: Checking system requirements.'); | 72 | $this->io->section('Step 1 of 4: Checking system requirements.'); |
74 | 73 | ||
75 | $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); | 74 | $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); |
76 | 75 | ||
@@ -169,7 +168,7 @@ class InstallCommand extends ContainerAwareCommand | |||
169 | 168 | ||
170 | protected function setupDatabase() | 169 | protected function setupDatabase() |
171 | { | 170 | { |
172 | $this->io->section('Step 2 of 5: Setting up database.'); | 171 | $this->io->section('Step 2 of 4: Setting up database.'); |
173 | 172 | ||
174 | // user want to reset everything? Don't care about what is already here | 173 | // user want to reset everything? Don't care about what is already here |
175 | if (true === $this->defaultInput->getOption('reset')) { | 174 | if (true === $this->defaultInput->getOption('reset')) { |
@@ -178,7 +177,7 @@ class InstallCommand extends ContainerAwareCommand | |||
178 | $this | 177 | $this |
179 | ->runCommand('doctrine:database:drop', ['--force' => true]) | 178 | ->runCommand('doctrine:database:drop', ['--force' => true]) |
180 | ->runCommand('doctrine:database:create') | 179 | ->runCommand('doctrine:database:create') |
181 | ->runCommand('doctrine:schema:create') | 180 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) |
182 | ->runCommand('cache:clear') | 181 | ->runCommand('cache:clear') |
183 | ; | 182 | ; |
184 | 183 | ||
@@ -192,7 +191,7 @@ class InstallCommand extends ContainerAwareCommand | |||
192 | 191 | ||
193 | $this | 192 | $this |
194 | ->runCommand('doctrine:database:create') | 193 | ->runCommand('doctrine:database:create') |
195 | ->runCommand('doctrine:schema:create') | 194 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) |
196 | ->runCommand('cache:clear') | 195 | ->runCommand('cache:clear') |
197 | ; | 196 | ; |
198 | 197 | ||
@@ -207,7 +206,7 @@ class InstallCommand extends ContainerAwareCommand | |||
207 | $this | 206 | $this |
208 | ->runCommand('doctrine:database:drop', ['--force' => true]) | 207 | ->runCommand('doctrine:database:drop', ['--force' => true]) |
209 | ->runCommand('doctrine:database:create') | 208 | ->runCommand('doctrine:database:create') |
210 | ->runCommand('doctrine:schema:create') | 209 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) |
211 | ; | 210 | ; |
212 | } elseif ($this->isSchemaPresent()) { | 211 | } elseif ($this->isSchemaPresent()) { |
213 | if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) { | 212 | if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) { |
@@ -215,14 +214,14 @@ class InstallCommand extends ContainerAwareCommand | |||
215 | 214 | ||
216 | $this | 215 | $this |
217 | ->runCommand('doctrine:schema:drop', ['--force' => true]) | 216 | ->runCommand('doctrine:schema:drop', ['--force' => true]) |
218 | ->runCommand('doctrine:schema:create') | 217 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) |
219 | ; | 218 | ; |
220 | } | 219 | } |
221 | } else { | 220 | } else { |
222 | $this->io->text('Creating schema...'); | 221 | $this->io->text('Creating schema...'); |
223 | 222 | ||
224 | $this | 223 | $this |
225 | ->runCommand('doctrine:schema:create') | 224 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) |
226 | ; | 225 | ; |
227 | } | 226 | } |
228 | 227 | ||
@@ -237,7 +236,7 @@ class InstallCommand extends ContainerAwareCommand | |||
237 | 236 | ||
238 | protected function setupAdmin() | 237 | protected function setupAdmin() |
239 | { | 238 | { |
240 | $this->io->section('Step 3 of 5: Administration setup.'); | 239 | $this->io->section('Step 3 of 4: Administration setup.'); |
241 | 240 | ||
242 | if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) { | 241 | if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) { |
243 | return $this; | 242 | return $this; |
@@ -272,7 +271,7 @@ class InstallCommand extends ContainerAwareCommand | |||
272 | 271 | ||
273 | protected function setupConfig() | 272 | protected function setupConfig() |
274 | { | 273 | { |
275 | $this->io->section('Step 4 of 5: Config setup.'); | 274 | $this->io->section('Step 4 of 4: Config setup.'); |
276 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); | 275 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
277 | 276 | ||
278 | // cleanup before insert new stuff | 277 | // cleanup before insert new stuff |
@@ -293,18 +292,6 @@ class InstallCommand extends ContainerAwareCommand | |||
293 | return $this; | 292 | return $this; |
294 | } | 293 | } |
295 | 294 | ||
296 | protected function runMigrations() | ||
297 | { | ||
298 | $this->io->section('Step 5 of 5: Run migrations.'); | ||
299 | |||
300 | $this | ||
301 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); | ||
302 | |||
303 | $this->io->text('<info>Migrations successfully executed.</info>'); | ||
304 | |||
305 | return $this; | ||
306 | } | ||
307 | |||
308 | /** | 295 | /** |
309 | * Run a command. | 296 | * Run a command. |
310 | * | 297 | * |
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index f684a206..bd351b18 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Command; | |||
5 | use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; | 5 | use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; |
6 | use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; | 6 | use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; |
7 | use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; | 7 | use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; |
8 | use Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand; | ||
8 | use Doctrine\DBAL\Platforms\PostgreSqlPlatform; | 9 | use Doctrine\DBAL\Platforms\PostgreSqlPlatform; |
9 | use Doctrine\DBAL\Platforms\SqlitePlatform; | 10 | use Doctrine\DBAL\Platforms\SqlitePlatform; |
10 | use Symfony\Bundle\FrameworkBundle\Console\Application; | 11 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
@@ -98,7 +99,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
98 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 99 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
99 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 100 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
100 | $this->assertContains('Config setup.', $tester->getDisplay()); | 101 | $this->assertContains('Config setup.', $tester->getDisplay()); |
101 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
102 | } | 102 | } |
103 | 103 | ||
104 | public function testRunInstallCommandWithReset() | 104 | public function testRunInstallCommandWithReset() |
@@ -125,7 +125,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
125 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 125 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
126 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 126 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
127 | $this->assertContains('Config setup.', $tester->getDisplay()); | 127 | $this->assertContains('Config setup.', $tester->getDisplay()); |
128 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
129 | 128 | ||
130 | // we force to reset everything | 129 | // we force to reset everything |
131 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 130 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
@@ -171,7 +170,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
171 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 170 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
172 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 171 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
173 | $this->assertContains('Config setup.', $tester->getDisplay()); | 172 | $this->assertContains('Config setup.', $tester->getDisplay()); |
174 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
175 | 173 | ||
176 | // the current database doesn't already exist | 174 | // the current database doesn't already exist |
177 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); | 175 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); |
@@ -198,7 +196,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
198 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 196 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
199 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 197 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
200 | $this->assertContains('Config setup.', $tester->getDisplay()); | 198 | $this->assertContains('Config setup.', $tester->getDisplay()); |
201 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
202 | 199 | ||
203 | $this->assertContains('Dropping schema and creating schema', $tester->getDisplay()); | 200 | $this->assertContains('Dropping schema and creating schema', $tester->getDisplay()); |
204 | } | 201 | } |
@@ -209,6 +206,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
209 | $application->add(new InstallCommand()); | 206 | $application->add(new InstallCommand()); |
210 | $application->add(new DropDatabaseDoctrineCommand()); | 207 | $application->add(new DropDatabaseDoctrineCommand()); |
211 | $application->add(new CreateDatabaseDoctrineCommand()); | 208 | $application->add(new CreateDatabaseDoctrineCommand()); |
209 | $application->add(new MigrationsMigrateDoctrineCommand()); | ||
212 | 210 | ||
213 | // drop database first, so the install command won't ask to reset things | 211 | // drop database first, so the install command won't ask to reset things |
214 | $command = new DropDatabaseDoctrineCommand(); | 212 | $command = new DropDatabaseDoctrineCommand(); |
@@ -242,7 +240,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
242 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 240 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
243 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 241 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
244 | $this->assertContains('Config setup.', $tester->getDisplay()); | 242 | $this->assertContains('Config setup.', $tester->getDisplay()); |
245 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
246 | 243 | ||
247 | $this->assertContains('Creating schema', $tester->getDisplay()); | 244 | $this->assertContains('Creating schema', $tester->getDisplay()); |
248 | } | 245 | } |
@@ -265,6 +262,5 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
265 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 262 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
266 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 263 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
267 | $this->assertContains('Config setup.', $tester->getDisplay()); | 264 | $this->assertContains('Config setup.', $tester->getDisplay()); |
268 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
269 | } | 265 | } |
270 | } | 266 | } |