protected function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); $manager = new \OC\DB\MDB2SchemaManager($this->connection); $manager->createDbFromStructure(__DIR__ . '/fixtures/dropoldtables.xml'); }
public function setUp() { parent::setUp(); $this->db = \OC::$server->getDatabaseConnection(); $manager = new \OC\DB\MDB2SchemaManager($this->db); $manager->createDbFromStructure(__DIR__ . '/contacts_schema.xml'); $this->adapter = new AddressBookAdapter($this->db); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('schema-xml'); $schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection()); try { $result = $schemaManager->updateDbFromStructure($file, true); $output->writeln($result); } catch (\Exception $e) { $output->writeln('Failed to update database structure (' . $e . ')'); } }
public function testAutoIncrement() { $connection = \OC_DB::getConnection(); if ($connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.'); } $manager = new \OC\DB\MDB2SchemaManager($connection); $manager->createDbFromStructure(__DIR__ . '/ts-autoincrement-before.xml'); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); $manager->updateDbFromStructure(__DIR__ . '/ts-autoincrement-after.xml'); $this->assertTrue(true); }
public function testAutoIncrement() { if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.'); } $connection = \OC_DB::getConnection(); $manager = new \OC\DB\MDB2SchemaManager($connection); $manager->createDbFromStructure(__DIR__ . '/ts-autoincrement-before.xml'); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); $manager->updateDbFromStructure(__DIR__ . '/ts-autoincrement-after.xml'); $this->assertTrue(true); }
public function testNonOCTables() { $manager = new \OC\DB\MDB2SchemaManager($this->connection); $manager->updateDbFromStructure(__DIR__ . '/testschema.xml'); $this->assertTrue(true); }
/** * creates the tables in migration.db from an apps database.xml * @param string $appid id of the app * @return bool whether the operation was successful */ private static function createAppTables($appid) { $schema_manager = new OC\DB\MDB2SchemaManager(self::$migration_database); // There is a database.xml file $content = file_get_contents(OC_App::getAppPath($appid) . '/appinfo/database.xml'); $file2 = 'static://db_scheme'; // TODO get the relative path to migration.db from the data dir // For now just cheat $path = pathinfo(self::$dbpath); $content = str_replace('*dbname*', self::$uid . '/migration', $content); $content = str_replace('*dbprefix*', '', $content); $xml = new SimpleXMLElement($content); foreach ($xml->table as $table) { $tables[] = (string) $table->name; } file_put_contents($file2, $content); // Try to create tables try { $schema_manager->createDbFromStructure($file2); } catch (Exception $e) { unlink($file2); OC_Log::write('migration', 'Failed to create tables for: ' . $appid, OC_Log::FATAL); OC_Log::write('migration', $e->getMessage(), OC_Log::FATAL); return false; } return $tables; }
protected function createSchema(Connection $toDB, InputInterface $input, OutputInterface $output) { $output->writeln('<info>Creating schema in new database</info>'); $schemaManager = new \OC\DB\MDB2SchemaManager($toDB); $schemaManager->createDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps(); foreach ($apps as $app) { if (file_exists(\OC_App::getAppPath($app) . '/appinfo/database.xml')) { $schemaManager->createDbFromStructure(\OC_App::getAppPath($app) . '/appinfo/database.xml'); } } }