/** * 根据实际定义的dbschema生成实际创建表的dbal schema * * @return \Doctrine\DBAL\Schema\Schema */ public function createTableSchema() { $appId = $this->target_app->app_id; $db = app::get($appId)->database(); $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable($this->real_table_name()); $define = $this->load(); // 建立字段 foreach ($define['columns'] as $columnName => $columnDefine) { list($type, $options) = $columnDefine['doctrineType']; $table->addColumn($columnName, $type, $options); } // 建立主键 //if ($define['pkeys']) $table->setPrimaryKey($define['pkeys']); if ($define['primary']) { $table->setPrimaryKey($define['primary']); } // 建立索引 if ($define['index']) { foreach ((array) $define['index'] as $indexName => $indexDefine) { if (strtolower($indexDefine['prefix']) == 'unique') { $table->addUniqueIndex($indexDefine['columns'], $indexName); } else { $table->addIndex($indexDefine['columns'], $indexName); } } } return $schema; }
public static function setUpBeforeClass() { self::$dbm = \TestHelperMw::getDBManager(); if (!self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL) { return; } $schema = new \Doctrine\DBAL\Schema\Schema(); $cacheTable = $schema->createTable('mw_cache_test'); $cacheTable->addColumn('id', 'string', array('length' => 255)); $cacheTable->addColumn('siteid', 'integer', array('notnull' => false)); $cacheTable->addColumn('expire', 'datetime', array('notnull' => false)); $cacheTable->addColumn('value', 'text', array('length' => 0xffff)); $cacheTable->addUniqueIndex(array('id', 'siteid')); $cacheTable->addIndex(array('expire')); $tagTable = $schema->createTable('mw_cache_tag_test'); $tagTable->addColumn('tid', 'string', array('length' => 255)); $tagTable->addColumn('tsiteid', 'integer', array('notnull' => false)); $tagTable->addColumn('tname', 'string', array('length' => 255)); $tagTable->addUniqueIndex(array('tid', 'tsiteid', 'tname')); $tagTable->addForeignKeyConstraint('mw_cache_test', array('tid', 'tsiteid'), array('id', 'siteid'), array('onDelete' => 'CASCADE')); $conn = self::$dbm->acquire(); foreach ($schema->toSQL($conn->getRawObject()->getDatabasePlatform()) as $sql) { $conn->create($sql)->execute()->finish(); } self::$dbm->release($conn); }
private function createSchema(\Doctrine\DBAL\Connection $connection) { $schema = new \Doctrine\DBAL\Schema\Schema(); $teams = $schema->createTable('teams'); $teams->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $teams->addColumn('uuid', 'binary', array('length' => 128)); $teams->addColumn('created_at', 'datetimetz'); $teams->addColumn('deleted', 'boolean', array('default' => false)); $teams->setPrimaryKey(array('id')); $players = $schema->createTable('players'); $players->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $players->addColumn('uuid', 'binary', array('length' => 128)); $players->addColumn('created_at', 'datetimetz'); $players->addColumn('deleted', 'boolean', array('default' => false)); $players->setPrimaryKey(array('id')); $teamsPlayers = $schema->createTable('teams_players'); $teamsPlayers->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $teamsPlayers->addColumn('uuid', 'binary', array('length' => 128)); $teamsPlayers->addColumn('created_at', 'datetimetz'); $teamsPlayers->addColumn('deleted', 'boolean', array('default' => false)); $teamsPlayers->addColumn('team_uuid', 'integer', array('unsigned' => true)); $teamsPlayers->addColumn('player_uuid', 'integer', array('unsigned' => true)); $teamsPlayers->setPrimaryKey(array('id')); foreach ($schema->toSql($connection->getDatabasePlatform()) as $query) { $connection->executeQuery($query); } }
/** * Migrate create schema */ public function migrateCreateSchema() { $entityName = $this->mapper->entity(); $table = $entityName::table(); $fields = $this->mapper->entityManager()->fields(); $fieldIndexes = $this->mapper->entityManager()->fieldKeys(); $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable($table); foreach ($fields as $field => $fieldInfo) { $fieldType = $fieldInfo['type']; unset($fieldInfo['type']); $table->addColumn($field, $fieldType, $fieldInfo); } // PRIMARY if ($fieldIndexes['primary']) { $table->setPrimaryKey($fieldIndexes['primary']); } // UNIQUE foreach ($fieldIndexes['unique'] as $keyName => $keyFields) { $table->addUniqueIndex($keyFields, $keyName); } // INDEX foreach ($fieldIndexes['index'] as $keyName => $keyFields) { $table->addIndex($keyFields, $keyName); } return $schema; }
/** * Helper method to run the actions needed for installation. */ protected function installSchema() { $schema = new \Doctrine\DBAL\Schema\Schema(); $samples = $schema->createTable('samples'); $samples->addColumn('version', 'string', array('length' => 32)); $samples->addColumn('when', 'datetime'); $samples->addColumn('notes', 'string', array('default' => '')); $samples->setPrimaryKey(array('version', 'when')); $sample_values = $schema->createTable('sample_values'); $sample_values->addColumn('version', 'string', array('length' => 32)); $sample_values->addColumn('when', 'datetime'); $sample_values->addColumn('key', 'string', array('length' => 64)); $sample_values->addColumn('value', 'smallint', array('notnull' => false)); $sample_values->setPrimaryKey(array('version', 'when', 'key')); $estimates = $schema->createTable('estimates'); $estimates->addColumn('version', 'string', array('length' => 32)); $estimates->addColumn('when', 'datetime'); $estimates->addColumn('started', 'datetime'); $estimates->addColumn('completed', 'datetime', array('notnull' => false)); $estimates->addColumn('estimate', 'datetime', array('notnull' => false)); $estimates->addColumn('note', 'string', array('default' => '')); $estimates->addColumn('data', 'blob'); $estimates->setPrimaryKey(array('version', 'when')); $state = $schema->createTable('state'); $state->addColumn('key', 'string', array('length' => 255)); $state->addColumn('value', 'blob'); $state->setPrimaryKey(array('key')); $synchronizer = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->app['db']); $synchronizer->createSchema($schema); // Create the version entry in the database. It will be updated with // the correct value at the end of `install()`. $this->app['db']->insert('state', array($this->app['db']->quoteIdentifier('key') => 'InstallationVersion', $this->app['db']->quoteIdentifier('value') => 0)); }
public function createTable($name) { // remove table $pdo = $this->pdo->query('DROP TABLE IF EXISTS `' . $name . '`;'); $pdo->execute(); // create table $newSchema = new \Doctrine\DBAL\Schema\Schema(); $newTable = $newSchema->createTable($name); $newTable->addColumn('container_id', 'integer'); $newTable->addColumn('context_id', 'integer'); $newTable->addColumn('module_id', 'integer'); $newTable->addColumn('resource_id', 'integer')->setNotnull(false); $newTable->addColumn('by_resource_id', 'integer')->setNotnull(false); $newTable->addColumn('sequence', 'integer')->setNotnull(false); $newTable->addColumn('deleted', 'datetime')->setNotnull(false); $newTable->addColumn('display', 'boolean')->setNotnull(true); $newTable->addColumn('expire_temporary_date', 'datetime')->setNotnull(false); $newTable->addColumn('culture', 'string')->setLength(11); foreach ($this->eavColumns->getColumns() as $column) { if ($this->getTypeToColumn($column['column'])) { $newTable->addColumn($column['identifier'], $this->getTypeToColumn($column['column']))->setNotnull(false); $columnsToFill[] = $column['identifier']; } } $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Container')->getTablename(), array('container_id'), array('container_id'), array('onDelete' => 'CASCADE')); $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Module')->getTablename(), array('module_id'), array('module_id'), array('onDelete' => 'CASCADE')); $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishContextBundle:Context')->getTablename(), array('context_id'), array('context_id'), array('onDelete' => 'CASCADE')); $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('resource_id'), array('resource_id'), array('onDelete' => 'CASCADE')); $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('by_resource_id'), array('resource_id'), array('onDelete' => 'CASCADE')); foreach ($newSchema->toSql($this->objectManager->getConnection()->getDatabasePlatform()) as $l) { $pdo = $this->pdo->prepare($l); $pdo->execute(); } }
public function repairTables() { $output = array(); $currentTables = $this->getTableObjects(); //$dboptions = getDBOptions($this->app['config']); /** @var $schemaManager AbstractSchemaManager */ $schemaManager = $this->app['db']->getSchemaManager(); $comparator = new Comparator(); $tables = array(); /* * Define table subscribers */ $schema = new \Doctrine\DBAL\Schema\Schema(); $subscribersTable = $schema->createTable($this->prefix . 'subscribers'); // Columns $subscribersTable->addColumn('id', 'integer', array('autoincrement' => true)); $subscribersTable->addColumn('email', 'string', array('length' => 64)); $subscribersTable->addColumn('confirmkey', 'string', array('length' => 64)); $subscribersTable->addColumn('datesubscribed', 'datetime', array('notNull' => false)); $subscribersTable->addColumn('confirmed', 'boolean'); $subscribersTable->addColumn('dateconfirmed', 'datetime', array('notNull' => false)); $subscribersTable->addColumn('active', 'boolean'); $subscribersTable->addColumn('dateunsubscribed', 'datetime', array('notNull' => false)); $subscribersTable->addColumn('unsubscribe_link', 'string', array('length' => 255, 'notNull' => false)); // Keys and indexes $subscribersTable->setPrimaryKey(array('id')); $subscribersTable->addUniqueIndex(array('email')); $subscribersTable->addUniqueIndex(array('confirmkey')); $tables[] = $subscribersTable; /* * Define table extra_fields */ $schema = new \Doctrine\DBAL\Schema\Schema(); $extraFieldsTable = $schema->createTable($this->prefix . 'extra_fields'); // Columns $extraFieldsTable->addColumn('id', 'integer', array('autoincrement' => true)); $extraFieldsTable->addColumn('subscribers_id', 'integer', array('unsigned' => true)); $extraFieldsTable->addColumn('name', 'string', array('length' => 30)); $extraFieldsTable->addColumn('value', 'string', array('length' => 255, 'notNull' => false)); // Keys and indexes $extraFieldsTable->setPrimaryKey(array('id')); $extraFieldsTable->addForeignKeyConstraint($subscribersTable, array('subscribers_id'), array('id'), array("onDelete" => "CASCADE")); $tables[] = $extraFieldsTable; /** @var $table Table */ foreach ($tables as $table) { // Create the tables if (!isset($currentTables[$table->getName()])) { /** @var $platform AbstractPlatform */ $platform = $this->app['db']->getDatabasePlatform(); $queries = $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES + AbstractPlatform::CREATE_FOREIGNKEYS); $queries = implode("; ", $queries); $this->app['db']->query($queries); $output[] = "Created table <tt>" . $table->getName() . "</tt>."; } } return $output; }
public function install() { $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable($this->getTableName()); $table->addColumn("id", "integer", array("unsigned" => true, 'autoincrement' => true)); $table->setPrimaryKey(array("id")); $table->addColumn('content', 'text'); $queries = $schema->toSql($this->app['db']->getDatabasePlatform()); $queries = implode("; ", $queries); $this->app['db']->query($queries); return true; }
public function parse($definition, \Concrete\Core\Database\Connection $db) { $schema = new \Doctrine\DBAL\Schema\Schema(); foreach ($definition as $tableName => $details) { if ($db->tableExists($tableName)) { continue; } $table = $schema->createTable($tableName); $table = $this->addColumns($table, $details['columns']); $table->setPrimaryKey($details['primary']); } return $schema; }
public function __construct() { $manager = \Database::connection()->getSchemaManager(); if (!$manager->tablesExist('OauthUserMap')) { $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('OauthUserMap'); $table->addColumn('user_id', 'integer', array('unsigned' => true)); $table->addColumn('binding', 'string', array('length' => 255)); $table->addColumn('namespace', 'string', array('length' => 255)); $table->setPrimaryKey(array('user_id', 'namespace')); $table->addUniqueIndex(array('binding', 'namespace'), 'oauth_binding'); $manager->createTable($table); } }
protected function setUp() { $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('mw_unit_test'); $table->addColumn('id', 'integer', array('autoincrement' => true)); $table->addColumn('name', 'string', array('length' => 20)); $table->setPrimaryKey(array('id')); $this->config = \TestHelperMw::getConfig(); $this->object = new \Aimeos\MW\DB\Manager\DBAL($this->config); $conn = $this->object->acquire(); foreach ($schema->toSQL($conn->getRawObject()->getDatabasePlatform()) as $sql) { $conn->create($sql)->execute()->finish(); } $this->object->release($conn); }
public function modify($columns = array(), $indexes = array(), $dryrun = false) { $synchronizer = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->conn); $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable($this->table); $primaryKey = ''; foreach ($columns as $name => $options) { $type = $options['type']; unset($options['type']); if (isset($options['primaryKey'])) { if ($options['primaryKey']) { if (!empty($primaryKey)) { throw new \Exception(_("Multiple Primary Keys defined")); } $primaryKey = $name; } unset($options['primaryKey']); } $table->addColumn($name, $type, $options); } if (!empty($primaryKey)) { $table->setPrimaryKey(array($primaryKey)); } foreach ($indexes as $name => $data) { $type = $data['type']; $columns = $data['cols']; switch ($type) { case "unique": $table->addUniqueIndex($columns, $name); break; case "index": $table->addIndex($columns, $name); break; case "fulltext": if ($this->driver == "pdo_mysql" && version_compare($this->version, "5.6", "le")) { $table->addOption('engine', 'MyISAM'); } $table->addIndex($columns, $name, array("fulltext")); break; } } //with true to prevent drops if ($dryrun) { return $synchronizer->getUpdateSchema($schema, true); } else { return $synchronizer->updateSchema($schema, true); } }
public function parse($definition, \Concrete\Core\Database\Connection\Connection $db) { $schema = new \Doctrine\DBAL\Schema\Schema(); foreach ($definition as $tableName => $details) { if ($db->tableExists($tableName)) { continue; } $table = $schema->createTable($tableName); if (isset($details['columns'])) { $table = $this->addColumns($table, $details['columns']); } else { throw new \Exception(t('Invalid column definition: %s in table %s', var_export($details, true), $tableName)); } $table->setPrimaryKey($details['primary']); } return $schema; }
public function setUp() { parent::setUp(); $platform = $this->_conn->getDatabasePlatform(); if ($platform->getName() == "sqlite") { $this->markTestSkipped('TableGenerator does not work with SQLite'); } try { $schema = new \Doctrine\DBAL\Schema\Schema(); $visitor = new \Doctrine\DBAL\Id\TableGeneratorSchemaVisitor(); $schema->visit($visitor); foreach ($schema->toSql($platform) as $sql) { $this->_conn->exec($sql); } } catch (\Exception $e) { } $this->generator = new TableGenerator($this->_conn); }
public static function setUpBeforeClass() { self::$dbm = \TestHelperMw::getDBManager(); if (!self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL) { return; } $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('mw_log_test'); $table->addColumn('facility', 'string', array('length' => 32)); $table->addColumn('request', 'string', array('length' => 32)); $table->addColumn('tstamp', 'string', array('length' => 20)); $table->addColumn('priority', 'integer', array()); $table->addColumn('message', 'text', array('length' => 0xffff)); $conn = self::$dbm->acquire(); foreach ($schema->toSQL($conn->getRawObject()->getDatabasePlatform()) as $sql) { $conn->create($sql)->execute()->finish(); } self::$dbm->release($conn); }
function dbal_hook_dbal(&$dbinfo) { $store = SimpleSAML_Store::getInstance(); if (!$store instanceof \SimpleSAML\Modules\DBAL\Store\DBAL) { throw new \SimpleSAML_Error_Exception('OAuth2 module: Only DBAL Store is supported'); } $prefix = $store->getPrefix() . '_kvstore'; $schema = new \Doctrine\DBAL\Schema\Schema(); $kvstore = $schema->createTable($prefix); $kvstore->addColumn('_type', 'string', array('length' => 30, 'notnull' => true)); $kvstore->addColumn('_key', 'string', array('length' => 50, 'notnull' => true)); $kvstore->addColumn('_value', 'text', array('notnull' => true)); $kvstore->addColumn('_expire', 'datetime', array('notnull' => false)); $kvstore->setPrimaryKey(array('_key', '_type')); $kvstore->addIndex(array('_expire')); // Update schema $store->createOrUpdateSchema($schema, $prefix); $dbinfo['summary'][] = 'Created Key-Value Schema'; }
public static function setUpBeforeClass() { self::$dbm = \TestHelperMw::getDBManager(); if (!self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL) { return; } $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('mw_mqueue_test'); $table->addColumn('id', 'integer', array('autoincrement' => true)); $table->addColumn('queue', 'string', array('length' => 255)); $table->addColumn('cname', 'string', array('length' => 32)); $table->addColumn('rtime', 'datetime', array()); $table->addColumn('message', 'text', array('length' => 0xffff)); $table->setPrimaryKey(array('id')); $conn = self::$dbm->acquire(); foreach ($schema->toSQL($conn->getRawObject()->getDatabasePlatform()) as $sql) { $conn->create($sql)->execute()->finish(); } self::$dbm->release($conn); }
public function getConnection() { $params = array('driver' => 'pdo_sqlite', 'memory' => true); $connection = DriverManager::getConnection($params, new Configuration()); $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('groups'); $table->addColumn('id', 'integer'); $table->addColumn('name', 'string', array('length' => 45)); $table->setPrimaryKey(array('id')); $myTable = $schema->createTable('user'); $myTable->addColumn('id', 'integer', array('unsigned' => true)); $myTable->addColumn('username', 'string', array('length' => 32)); $myTable->addColumn('group_id', 'integer'); $myTable->setPrimaryKey(array('id')); $myTable->addUniqueIndex(array('username')); $myTable->addForeignKeyConstraint($table, array('group_id'), array('id')); foreach ($schema->toSql(new SqlitePlatform()) as $query) { $connection->query($query); } return $connection; }
/** * @author "Lionel Lecaque, <*****@*****.**>" */ public function destroyTaoDatabase() { $platform = $this->connection->getDatabasePlatform(); $queries = $this->schema->toDropSql($platform); foreach ($queries as $query) { $this->connection->executeUpdate($query); } //drop sequence $sm = $this->getSchemaManager(); $sequences = $sm->listSequences(); foreach ($sequences as $name) { $sm->dropSequence($name); } }
public static function setUpBeforeClass() { self::$dbm = \TestHelperMw::getDBManager(); if (!self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL) { return; } $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable('mw_tree_test'); $table->addColumn('id', 'integer', array('autoincrement' => true)); $table->addColumn('parentid', 'integer', array('notnull' => false)); $table->addColumn('label', 'string', array('length' => 16)); $table->addColumn('code', 'string', array('length' => 32)); $table->addColumn('level', 'integer', array()); $table->addColumn('nleft', 'integer', array()); $table->addColumn('nright', 'integer', array()); $table->addColumn('status', 'smallint', array()); $table->setPrimaryKey(array('id')); $conn = self::$dbm->acquire(); foreach ($schema->toSQL($conn->getRawObject()->getDatabasePlatform()) as $sql) { $conn->create($sql)->execute()->finish(); } self::$dbm->release($conn); }
/** * Transforms the XML from Adodb XML into * Doctrine DBAL Schema. */ public function parse(\Concrete\Core\Database\Connection\Connection $db) { $x = $this->rawXML; $schema = new \Doctrine\DBAL\Schema\Schema(); foreach ($x->table as $t) { if ($this->ignoreExistingTables && $db->tableExists($t['name'])) { continue; } $table = $schema->createTable((string) $t['name']); foreach ($t->field as $f) { $options = $this->_getColumnOptions($db, $f); $version = isset($options['version']) && $options['version'] ? true : false; unset($options['version']); $field = $table->addColumn((string) $f['name'], $this->_getColumnType($f), $options); if ($version) { $field->setPlatformOption('version', true); } } $this->_setPrimaryKeys($db, $t, $table); $this->_setIndexes($db, $t, $table); $this->_setTableOpts($db, $t, $table); } return $schema; }
function oauth2_hook_dbal(&$dbinfo) { $store = SimpleSAML_Store::getInstance(); if (!$store instanceof \SimpleSAML\Modules\DBAL\Store\DBAL) { throw new \SimpleSAML_Error_Exception('OAuth2 module: Only DBAL Store is supported'); } $schema = new \Doctrine\DBAL\Schema\Schema(); $clientTable = $store->getPrefix() . '_oauth2_client'; $client = $schema->createTable($clientTable); $client->addColumn('id', 'string', ['length' => 255]); $client->addColumn('secret', 'string', ['length' => 255]); $client->addColumn('name', 'string', ['length' => 255]); $client->addColumn('description', 'text', ['notnull' => false]); $client->addColumn('redirect_uri', 'json_array'); $client->addColumn('scopes', 'json_array'); $client->setPrimaryKey(['id']); $accesstokenTable = $store->getPrefix() . '_oauth2_accesstoken'; $accesstoken = $schema->createTable($accesstokenTable); $accesstoken->addColumn('id', 'string', ['length' => 255]); $accesstoken->addColumn('scopes', 'json_array', ['notnull' => false]); $accesstoken->addColumn('attributes', 'json_array', ['notnull' => false]); $accesstoken->addColumn('expires_at', 'datetime'); $accesstoken->addColumn('user_id', 'string', ['length' => 255]); $accesstoken->addColumn('client_id', 'string', ['length' => 255]); $accesstoken->addColumn('is_revoked', 'boolean', ['default' => false]); $accesstoken->setPrimaryKey(['id']); $accesstoken->addForeignKeyConstraint($clientTable, ['client_id'], ['id'], ['onDelete' => 'CASCADE']); $refreshtokenTable = $store->getPrefix() . '_oauth2_refreshtoken'; $refreshtoken = $schema->createTable($refreshtokenTable); $refreshtoken->addColumn('id', 'string', ['length' => 255]); $refreshtoken->addColumn('expires_at', 'datetime'); $refreshtoken->addColumn('accesstoken_id', 'string', ['length' => 255]); $refreshtoken->addColumn('is_revoked', 'boolean', ['default' => false]); $refreshtoken->setPrimaryKey(['id']); $refreshtoken->addForeignKeyConstraint($accesstokenTable, ['accesstoken_id'], ['id'], ['onDelete' => 'CASCADE']); $authcodeTable = $store->getPrefix() . '_oauth2_authcode'; $authcode = $schema->createTable($authcodeTable); $authcode->addColumn('id', 'string', ['length' => 255]); $authcode->addColumn('scopes', 'json_array'); $authcode->addColumn('expires_at', 'datetime'); $authcode->addColumn('user_id', 'string', ['length' => 255]); $authcode->addColumn('client_id', 'string', ['length' => 255]); $authcode->addColumn('is_revoked', 'boolean', ['default' => false]); $authcode->addColumn('redirect_uri', 'text'); $authcode->addForeignKeyConstraint($clientTable, ['client_id'], ['id'], ['onDelete' => 'CASCADE']); $store->createOrUpdateSchema($schema, $store->getPrefix() . '_oauth2'); $dbinfo['summary'][] = 'Created OAuth2 Schema'; }
public function convert(\Cti\Storage\Schema $inputSchema) { $schema = new \Doctrine\DBAL\Schema\Schema(); foreach ($inputSchema->getModels() as $model) { $table = $schema->createTable($model->getName()); foreach ($model->getProperties() as $property) { $params = array('comment' => $property->getComment(), 'notnull' => $property->getRequired()); $type = $property->getType(); if ($type === 'char') { $type = 'string'; $params['length'] = 1; } $table->addColumn($property->getName(), $type, $params); } $table->setPrimaryKey($model->getPk()); foreach ($model->getIndexes() as $index) { $table->addIndex($index->getFields()); } } foreach ($inputSchema->getModels() as $model) { $table = $schema->getTable($model->getName()); foreach ($model->getOutReferences() as $reference) { if ($inputSchema->getModel($reference->getDestination())->getBehaviour("log")) { continue; } $destination = $schema->getTable($reference->getDestination()); $foreignProperties = array(); foreach ($reference->getProperties() as $property) { $foreignProperties[] = $property->getForeignName(); } $localProperties = array_keys($reference->getProperties()); $table->addForeignKeyConstraint($destination, $localProperties, $foreignProperties); } } foreach ($inputSchema->getSequences() as $sequence) { $schema->createSequence($sequence->getName()); } return $schema; }
public function sql() { $functions = "CREATE TABLE `function` (`id`\tINTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT UNIQUE, `type` TEXT, `description` TEXT"; $params = "CREATE TABLE `parameter` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `parameter` TEXT NOT NULL, `type` TEXT NOT NULL, `initializer`\tTEXT, `functionId` INTEGER NOT NULL"; $schema = new \Doctrine\DBAL\Schema\Schema(); $functions = $schema->createTable('function'); $functions->addColumn('id', 'integer', array('autoincrement' => true)); $functions->addColumn('name', 'text'); $functions->addColumn('type', 'text'); $functions->addColumn('description', 'text'); $functions->setPrimaryKey(array('id')); $functions->addUniqueIndex(array('name')); $schema->createSequence('function_seq'); $parameter = $schema->createTable('parameter'); $parameter->addColumn('id', 'integer', array('autoincrement' => true)); $parameter->addColumn('parameter', 'text'); $parameter->addColumn('type', 'text'); $parameter->addColumn('initializer', 'text'); $parameter->setPrimaryKey(array('id')); $schema->createSequence('parameter_seq'); $sql = $schema->toSql(new \Doctrine\DBAL\Platforms\SqlitePlatform()); var_dump($sql); die; }
/** * @dataProvider getConnectionParams */ public function testConnectionException($params) { if ($this->_conn->getDatabasePlatform()->getName() == 'sqlite') { $this->markTestSkipped("Only skipped if platform is not sqlite"); } if ($this->_conn->getDatabasePlatform()->getName() == 'drizzle') { $this->markTestSkipped("Drizzle does not always support authentication"); } if ($this->_conn->getDatabasePlatform()->getName() == 'postgresql' && isset($params['password'])) { $this->markTestSkipped("Does not work on Travis"); } $defaultParams = $this->_conn->getParams(); $params = array_merge($defaultParams, $params); $conn = \Doctrine\DBAL\DriverManager::getConnection($params); $schema = new \Doctrine\DBAL\Schema\Schema(); $table = $schema->createTable("no_connection"); $table->addColumn('id', 'integer'); $this->setExpectedException('Doctrine\\DBAL\\Exception\\ConnectionException'); foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { $conn->executeQuery($sql); } }
<?php /** * @author Саша Стаменковић <*****@*****.**> */ $schema = new \Doctrine\DBAL\Schema\Schema(); $gloves = $schema->createTable('ismartbrowse_orders'); $gloves->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $gloves->addColumn('firstName', 'string', array('length' => 255)); $gloves->addColumn('lastName', 'string', array('length' => 255)); $gloves->addColumn('address1Billing', 'string', array('length' => 255)); $gloves->addColumn('address2Billing', 'string', array('length' => 255)); $gloves->addColumn('zipBilling', 'string', array('length' => 255)); $gloves->addColumn('cityBilling', 'string', array('length' => 255)); $gloves->addColumn('stateBilling', 'string', array('length' => 255)); $gloves->addColumn('countryBilling', 'string', array('length' => 255)); $gloves->addColumn('address1Shipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('address2Shipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('zipShipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('cityShipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('stateShipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('countryShipping', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('email', 'string', array('length' => 255)); $gloves->addColumn('gender', 'string', array('length' => 1)); $gloves->addColumn('quantity', 'integer', array('length' => 11)); $gloves->addColumn('paymentChoice', 'integer', array('length' => 2)); $gloves->addColumn('sameAsShipping', 'integer', array('length' => 2)); $gloves->addColumn('trackingNumber', 'string', array('length' => 255, 'notnull' => false)); $gloves->addColumn('shipped', 'boolean', array('notnull' => false)); $gloves->setPrimaryKey(array('id')); return $schema;
/** * From a given set of metadata classes this method creates a Schema instance. * * @param array $classes * @return Schema */ public function getSchemaFromMetadata(array $classes) { $processedClasses = array(); // Reminder for processed classes, used for hierarchies $metadataSchemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig(); $metadataSchemaConfig->setExplicitForeignKeyIndexes(false); $metadataSchemaConfig->setMaxIdentifierLength(63); $sm = $this->_em->getConnection()->getSchemaManager(); $schema = new \Doctrine\DBAL\Schema\Schema(array(), array(), $metadataSchemaConfig); foreach ($classes as $class) { if (isset($processedClasses[$class->name]) || $class->isMappedSuperclass) { continue; } $table = $schema->createTable($class->getQuotedTableName($this->_platform)); if ($class->isIdGeneratorIdentity()) { $table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY); } else { if ($class->isIdGeneratorSequence()) { $table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_SEQUENCE); } } $columns = array(); // table columns if ($class->isInheritanceTypeSingleTable()) { $columns = $this->_gatherColumns($class, $table); $this->_gatherRelationsSql($class, $table, $schema); // Add the discriminator column $discrColumnDef = $this->_getDiscriminatorColumnDefinition($class, $table); // Aggregate all the information from all classes in the hierarchy foreach ($class->parentClasses as $parentClassName) { // Parent class information is already contained in this class $processedClasses[$parentClassName] = true; } foreach ($class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); $this->_gatherColumns($subClass, $table); $this->_gatherRelationsSql($subClass, $table, $schema); $processedClasses[$subClassName] = true; } } else { if ($class->isInheritanceTypeJoined()) { // Add all non-inherited fields as columns $pkColumns = array(); foreach ($class->fieldMappings as $fieldName => $mapping) { if (!isset($mapping['inherited'])) { $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform); $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($fieldName)) { $pkColumns[] = $columnName; } } } $this->_gatherRelationsSql($class, $table, $schema); // Add the discriminator column only to the root table if ($class->name == $class->rootEntityName) { $discrColumnDef = $this->_getDiscriminatorColumnDefinition($class, $table); } else { // Add an ID FK column to child tables /* @var Doctrine\ORM\Mapping\ClassMetadata $class */ $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); $pkColumns[] = $columnName; if ($table->isIdGeneratorIdentity()) { $table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_NONE); } // Add a FK constraint on the ID column $table->addUnnamedForeignKeyConstraint($this->_em->getClassMetadata($class->rootEntityName)->getQuotedTableName($this->_platform), array($columnName), array($columnName), array('onDelete' => 'CASCADE')); } $table->setPrimaryKey($pkColumns); } else { if ($class->isInheritanceTypeTablePerClass()) { throw DoctrineException::notSupported(); } else { $this->_gatherColumns($class, $table); $this->_gatherRelationsSql($class, $table, $schema); } } } if (isset($class->primaryTable['indexes'])) { foreach ($class->primaryTable['indexes'] as $indexName => $indexData) { $table->addIndex($indexData['columns'], $indexName); } } if (isset($class->primaryTable['uniqueConstraints'])) { foreach ($class->primaryTable['uniqueConstraints'] as $indexName => $indexData) { $table->addUniqueIndex($indexData['columns'], $indexName); } } $processedClasses[$class->name] = true; if ($class->isIdGeneratorSequence() && $class->name == $class->rootEntityName) { $seqDef = $class->getSequenceGeneratorDefinition(); if (!$schema->hasSequence($seqDef['sequenceName'])) { $schema->createSequence($seqDef['sequenceName'], $seqDef['allocationSize'], $seqDef['initialValue']); } } } return $schema; }
<?php /* For license terms, see /license.txt */ /** * Plugin database installation script. Can only be executed if included * inside another script loading global.inc.php * @package chamilo.plugin.buycourses */ /** * Check if script can be called */ if (!function_exists('api_get_path')) { die('This script must be loaded through the Chamilo plugin installer sequence'); } $entityManager = Database::getManager(); $pluginSchema = new \Doctrine\DBAL\Schema\Schema(); $connection = $entityManager->getConnection(); $platform = $connection->getDatabasePlatform(); //Create tables $paypalTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_PAYPAL); $paypalTable->addColumn('id', \Doctrine\DBAL\Types\Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]); $paypalTable->addColumn('username', \Doctrine\DBAL\Types\Type::STRING); $paypalTable->addColumn('password', \Doctrine\DBAL\Types\Type::STRING); $paypalTable->addColumn('signature', \Doctrine\DBAL\Types\Type::STRING); $paypalTable->addColumn('sandbox', \Doctrine\DBAL\Types\Type::BOOLEAN); $paypalTable->setPrimaryKey(['id']); $transferTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_TRANSFER); $transferTable->addColumn('id', \Doctrine\DBAL\Types\Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]); $transferTable->addColumn('name', \Doctrine\DBAL\Types\Type::STRING); $transferTable->addColumn('account', \Doctrine\DBAL\Types\Type::STRING); $transferTable->addColumn('swift', \Doctrine\DBAL\Types\Type::STRING);
/** * From a given set of metadata classes this method creates a Schema instance. * * @param array $classes * @return Schema */ public function getSchemaFromMetadata(array $classes) { $processedClasses = array(); // Reminder for processed classes, used for hierarchies $sm = $this->_em->getConnection()->getSchemaManager(); $metadataSchemaConfig = $sm->createSchemaConfig(); $metadataSchemaConfig->setExplicitForeignKeyIndexes(false); $schema = new \Doctrine\DBAL\Schema\Schema(array(), array(), $metadataSchemaConfig); $evm = $this->_em->getEventManager(); foreach ($classes as $class) { if ($this->processingNotRequired($class, $processedClasses)) { continue; } $table = $schema->createTable($class->getQuotedTableName($this->_platform)); $columns = array(); // table columns if ($class->isInheritanceTypeSingleTable()) { $columns = $this->_gatherColumns($class, $table); $this->_gatherRelationsSql($class, $table, $schema); // Add the discriminator column $discrColumnDef = $this->_getDiscriminatorColumnDefinition($class, $table); // Aggregate all the information from all classes in the hierarchy foreach ($class->parentClasses as $parentClassName) { // Parent class information is already contained in this class $processedClasses[$parentClassName] = true; } foreach ($class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); $this->_gatherColumns($subClass, $table); $this->_gatherRelationsSql($subClass, $table, $schema); $processedClasses[$subClassName] = true; } } else { if ($class->isInheritanceTypeJoined()) { // Add all non-inherited fields as columns $pkColumns = array(); foreach ($class->fieldMappings as $fieldName => $mapping) { if (!isset($mapping['inherited'])) { $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform); $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($fieldName)) { $pkColumns[] = $columnName; } } } $this->_gatherRelationsSql($class, $table, $schema); // Add the discriminator column only to the root table if ($class->name == $class->rootEntityName) { $discrColumnDef = $this->_getDiscriminatorColumnDefinition($class, $table); } else { // Add an ID FK column to child tables /* @var Doctrine\ORM\Mapping\ClassMetadata $class */ $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); // TODO: This seems rather hackish, can we optimize it? $table->getColumn($class->identifier[0])->setAutoincrement(false); $pkColumns[] = $columnName; // Add a FK constraint on the ID column $table->addUnnamedForeignKeyConstraint($this->_em->getClassMetadata($class->rootEntityName)->getTableName(), array($columnName), array($columnName), array('onDelete' => 'CASCADE')); } $table->setPrimaryKey($pkColumns); } else { if ($class->isInheritanceTypeTablePerClass()) { throw ORMException::notSupported(); } else { $this->_gatherColumns($class, $table); $this->_gatherRelationsSql($class, $table, $schema); } } } if (isset($class->table['indexes'])) { foreach ($class->table['indexes'] as $indexName => $indexData) { $table->addIndex($indexData['columns'], $indexName); } } if (isset($class->table['uniqueConstraints'])) { foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) { $table->addUniqueIndex($indexData['columns'], $indexName); } } $processedClasses[$class->name] = true; if ($class->isIdGeneratorSequence() && $class->name == $class->rootEntityName) { $seqDef = $class->sequenceGeneratorDefinition; if (!$schema->hasSequence($seqDef['sequenceName'])) { $schema->createSequence($seqDef['sequenceName'], $seqDef['allocationSize'], $seqDef['initialValue']); } } if ($evm->hasListeners(ToolEvents::postGenerateSchemaTable)) { $evm->dispatchEvent(ToolEvents::postGenerateSchemaTable, new GenerateSchemaTableEventArgs($class, $schema, $table)); } } if ($evm->hasListeners(ToolEvents::postGenerateSchema)) { $evm->dispatchEvent(ToolEvents::postGenerateSchema, new GenerateSchemaEventArgs($this->_em, $schema)); } return $schema; }
<?php /** * @author Саша Стаменковић <*****@*****.**> */ $schema = new \Doctrine\DBAL\Schema\Schema(); $post = $schema->createTable('post'); $post->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $post->addColumn('title', 'string', array('length' => 32)); $post->setPrimaryKey(array('id')); return $schema;