Example #1
0
 protected function doExecute()
 {
     $this->step('Creating schema');
     $configuration = new \Firenote\Configuration\Yaml($this->rootPath . 'config');
     $app = new \Firenote\Application($configuration);
     $this->createDatabase($configuration);
     $schema = $app['db']->getSchemaManager();
     if (!$schema instanceof \Doctrine\DBAL\Schema\AbstractSchemaManager) {
         throw new \Exception();
     }
     if (!$schema->tablesExist('users')) {
         $this->writeln('<info>Creating table users ...</info>');
         $users = new Table('users');
         $users->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
         $users->setPrimaryKey(array('id'));
         $users->addColumn('username', 'string', array('length' => 32));
         $users->addUniqueIndex(array('username'));
         $users->addColumn('password', 'string', array('length' => 255));
         $users->addColumn('roles', 'string', array('length' => 255));
         $users->addColumn('avatar', 'string', array('length' => 512));
         $schema->createTable($users);
         $this->writeln('<info>Adding admin user (admin/foo) ...</info>');
         $this->writeln('<comment>Please change this dummy password !</comment>');
         $app['db']->insert('users', array('username' => 'admin', 'password' => '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==', 'roles' => 'ROLE_ADMIN', 'avatar' => '/assets/firenote/avatars/avatar2.png'));
     } else {
         $this->writeln('Nothing to do !');
     }
 }
Example #2
0
 private function createTable($name)
 {
     $table = new Schema\Table($this->tableName($name));
     $table->addColumn('id', Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]);
     $table->setPrimaryKey(['id']);
     return $table;
 }
Example #3
0
 /**
  * Drops the tables and rebuilds them
  */
 public function rebuildSchema()
 {
     $schemaManager = $this->conn->getSchemaManager();
     $productTable = new Table('product');
     $productTable->addColumn("id", "integer", array("unsigned" => true));
     $productTable->addColumn("name", "string", array("length" => 255));
     $productTable->addColumn('author_id', 'integer', array('notNull' => false));
     $productTable->addColumn("description", "text", array('notNull' => false));
     $productTable->addColumn("price", "decimal", array('scale' => 2, 'notNull' => false));
     $productTable->addColumn("is_published", "boolean");
     $productTable->addColumn('created_at', 'datetime');
     $productTable->setPrimaryKey(array("id"));
     $schemaManager->dropAndCreateTable($productTable);
     $userTable = new Table('user');
     $userTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
     $userTable->setPrimaryKey(array('id'));
     $userTable->addColumn('username', 'string', array('length' => 32));
     $userTable->addUniqueIndex(array('username'));
     $userTable->addColumn('password', 'string', array('length' => 255));
     $userTable->addColumn('roles', 'string', array('length' => 255));
     $userTable->addColumn('created_at', 'datetime');
     // add an author_id to product
     $productTable->addForeignKeyConstraint($userTable, array('author_id'), array('id'));
     $schemaManager->dropAndCreateTable($userTable);
 }
 /**
  * @group DDC-1337
  * @return void
  */
 public function testCreateTemporaryTableNotAutoCommitTransaction()
 {
     if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || $this->_conn->getDatabasePlatform()->getName() == 'oracle') {
         $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere.");
     }
     $platform = $this->_conn->getDatabasePlatform();
     $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
     $tempTable = $platform->getTemporaryTableName("my_temporary");
     $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
     $table = new Table("nontemporary");
     $table->addColumn("id", "integer");
     $table->setPrimaryKey(array('id'));
     foreach ($platform->getCreateTableSQL($table) as $sql) {
         $this->_conn->executeQuery($sql);
     }
     $this->_conn->beginTransaction();
     $this->_conn->insert("nontemporary", array("id" => 1));
     $this->_conn->exec($createTempTableSQL);
     $this->_conn->insert("nontemporary", array("id" => 2));
     $this->_conn->rollback();
     try {
         $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
     } catch (\Exception $e) {
     }
     $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
     $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
 }
Example #5
0
 /**
  * Exports create table SQL.
  *
  * @return string
  */
 protected function exportCreateTable()
 {
     $table = new Table(self::TABLE_NAME, array(), array(), array(), false, array());
     $table->addColumn('id', 'string', array('length' => 2, 'notnull' => true));
     $table->setPrimaryKey(array('id'));
     $table->addColumn('value', 'string', array('length' => 64));
     return array_pop($this->getConnection()->getDatabasePlatform()->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)) . ';' . PHP_EOL;
 }
 public function testSearchPathSchemaChanges()
 {
     $table = new Table("dbal510tbl");
     $table->addColumn('id', 'integer');
     $table->setPrimaryKey(array('id'));
     $this->_conn->getSchemaManager()->createTable($table);
     $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl');
     $comparator = new Comparator();
     $diff = $comparator->diffTable($onlineTable, $table);
     $this->assertFalse($diff);
 }
 public function testListTableColumnsWithFixedStringTypeColumn()
 {
     $table = new Table('list_table_columns_char');
     $table->addColumn('id', 'integer', array('notnull' => true));
     $table->addColumn('test', 'string', array('fixed' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $columns = $this->_sm->listTableColumns('list_table_columns_char');
     $this->assertArrayHasKey('test', $columns);
     $this->assertTrue($columns['test']->getFixed());
 }
 /**
  * Builds table structure.
  *
  * @param Table $table
  */
 protected function buildTable(Table $table)
 {
     $table->addColumn('id', 'bigint')->setUnsigned(true)->setAutoincrement(true);
     $table->addColumn('type', 'string')->setLength(1)->setComment('C-CREATE(INSERT),U-UPDATE,D-DELETE');
     $table->addColumn('document_type', 'string')->setLength(32);
     $table->addColumn('document_id', 'string')->setLength(32);
     $table->addColumn('timestamp', 'datetime');
     $table->addColumn('status', 'boolean', ['default' => self::STATUS_NEW])->setComment('0-new,1-inProgress,2-error');
     $table->setPrimaryKey(['id']);
     $table->addUniqueIndex(['type', 'document_type', 'document_id', 'status']);
 }
Example #9
0
 public function createTable()
 {
     if ($this->isExistTable()) {
         return;
     }
     $table = new Table(self::TABLE_NAME);
     $table->addColumn('version', Type::STRING, array('length' => 255, 'notnull' => true, 'default' => ''));
     $table->addColumn('apply_at', Type::DATETIME, array('notnull' => false, 'default' => null));
     $table->setPrimaryKey(array('version'));
     $this->doctrine->getSchemaManager()->createTable($table);
 }
Example #10
0
 public function testSwitchPrimaryKeyOrder()
 {
     $tableOld = new Table("test");
     $tableOld->addColumn('foo_id', 'integer');
     $tableOld->addColumn('bar_id', 'integer');
     $tableNew = clone $tableOld;
     $tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
     $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
     $diff = $this->comparator->diffTable($tableOld, $tableNew);
     $sql = $this->platform->getAlterTableSQL($diff);
     $this->assertEquals(array('ALTER TABLE test DROP PRIMARY KEY', 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'), $sql);
 }
 /**
  * @group DDC-1657
  */
 public function testIsAutoincrementFor()
 {
     $table = new Table("foo");
     $table->addColumn("id", "integer", array("autoincrement" => true));
     $table->setPrimaryKey(array("id"));
     $sequence = new Sequence("foo_id_seq");
     $sequence2 = new Sequence("bar_id_seq");
     $sequence3 = new Sequence("other.foo_id_seq");
     $this->assertTrue($sequence->isAutoIncrementsFor($table));
     $this->assertFalse($sequence2->isAutoIncrementsFor($table));
     $this->assertFalse($sequence3->isAutoIncrementsFor($table));
 }
 public function testListTableWithBinary()
 {
     $tableName = 'test_binary_table';
     $table = new Table($tableName);
     $table->addColumn('id', 'integer');
     $table->addColumn('column_varbinary', 'binary', array());
     $table->addColumn('column_binary', 'binary', array('fixed' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->createTable($table);
     $table = $this->_sm->listTableDetails($tableName);
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\BinaryType', $table->getColumn('column_varbinary')->getType());
     $this->assertFalse($table->getColumn('column_varbinary')->getFixed());
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\BinaryType', $table->getColumn('column_binary')->getType());
     $this->assertFalse($table->getColumn('column_binary')->getFixed());
 }
 public function testUniquePrimaryKey()
 {
     $keyTable = new Table("foo");
     $keyTable->addColumn("bar", "integer");
     $keyTable->addColumn("baz", "string");
     $keyTable->setPrimaryKey(array("bar"));
     $keyTable->addUniqueIndex(array("baz"));
     $oldTable = new Table("foo");
     $oldTable->addColumn("bar", "integer");
     $oldTable->addColumn("baz", "string");
     $c = new \Doctrine\DBAL\Schema\Comparator();
     $diff = $c->diffTable($oldTable, $keyTable);
     $sql = $this->_platform->getAlterTableSQL($diff);
     $this->assertEquals(array("ALTER TABLE foo ADD PRIMARY KEY (bar)", "CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)"), $sql);
 }
Example #14
0
 /**
  * @group DBAL-464
  */
 public function testDropPrimaryKeyWithAutoincrementColumn()
 {
     $table = new Table("drop_primary_key");
     $table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
     $table->addColumn('foo', 'integer', array('primary' => true));
     $table->setPrimaryKey(array('id', 'foo'));
     $this->_sm->dropAndCreateTable($table);
     $diffTable = clone $table;
     $diffTable->dropPrimaryKey();
     $comparator = new Comparator();
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $table = $this->_sm->listTableDetails("drop_primary_key");
     $this->assertFalse($table->hasPrimaryKey());
     $this->assertFalse($table->getColumn('id')->getAutoincrement());
 }
 /**
  * Defines the table at the specified version
  * 
  * @param Table  $table   Table
  * @param string $version Version
  */
 public function define(Table $table, $version)
 {
     switch (true) {
         // Version 0.1.0
         case version_compare($version, "0.1.0", '>='):
             $table->addColumn('id', 'integer')->setUnsigned(true)->setNotNull(true)->setAutoIncrement(true)->setComment('Timezone ID (local db)');
             $table->addColumn('country_id', 'integer')->setUnsigned(true)->setNotNull(true)->setComment('Country (=> ' . CountryTableDefinition::NAME . '.id)');
             $table->addColumn('code', 'string')->setLength(50)->setNotNull(false)->setComment("Timezone code");
             // Primary key
             $table->setPrimaryKey(['id'], 'PK_GeoTimezone_id');
             // Foriegn keys
             $table->addNamedForeignKeyConstraint('FK_GeoTimezone_country', CountryTableDefinition::NAME, ['country_id'], ['id']);
             // Unique Keys
             $table->addUniqueIndex(['code'], 'UK_GeoTimezone_code');
     }
 }
 public function testEncodedForeignKeyConstraintNameIsTheSameAsDoctrineDefault()
 {
     $tableName1 = 'tbl123456789012345';
     $columnName1 = 'clmn1234567890';
     $tableName2 = 'tbl1234567890';
     $columnName2 = 'clmn12345';
     $table1 = new Table($tableName1, [new Column($columnName1, Type::getType('integer'))]);
     $table2 = new Table($tableName2, [new Column($columnName2, Type::getType('integer'))]);
     $table2->setPrimaryKey([$columnName2]);
     $table1->addForeignKeyConstraint($table2, [$columnName1], [$columnName2]);
     $foreignKeys = $table1->getForeignKeys();
     $doctrineResult = array_pop($foreignKeys)->getName();
     $generator = new DbIdentifierNameGenerator();
     $result = $generator->generateForeignKeyConstraintName($tableName1, [$columnName1]);
     $this->assertEquals($doctrineResult, $result);
 }
 /**
  * @param string $name Specifies the table name.
  * @param array $columns A list of the table columns.
  * @return Doctrine\DBAL\Schema\Table Returns the table schema.
  */
 public function createTableSchema($name, $columns)
 {
     $schema = new Table($name);
     $primaryKeyColumns = [];
     foreach ($columns as $column) {
         $type = trim($column['type']);
         $typeName = MigrationColumnType::toDoctrineTypeName($type);
         $options = $this->formatOptions($type, $column);
         $schema->addColumn($column['name'], $typeName, $options);
         if ($column['primary_key']) {
             $primaryKeyColumns[] = $column['name'];
         }
     }
     if ($primaryKeyColumns) {
         $schema->setPrimaryKey($primaryKeyColumns);
     }
     return $schema;
 }
Example #18
0
 public function __construct(Application $app)
 {
     $this->app = $app;
     $this->db = $app['db'];
     $schema = $this->db->getSchemaManager();
     if (!$schema->tablesExist('users')) {
         $users = new Table('users');
         $users->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
         $users->setPrimaryKey(array('id'));
         $users->addColumn('username', 'string', array('length' => 32));
         $users->addUniqueIndex(array('username'));
         $users->addColumn('password', 'string', array('length' => 255));
         $users->addColumn('roles', 'string', array('length' => 255));
         $schema->createTable($users);
         $app['db']->insert('users', array('username' => 'fabien', 'password' => '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==', 'roles' => 'ROLE_USER'));
         $app['db']->insert('users', array('username' => 'admin', 'password' => '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==', 'roles' => 'ROLE_ADMIN'));
     }
 }
Example #19
0
 /**
  * Создание таблицы пользователей
  *
  * @param App $app
  * @return string
  */
 public function createAction(App $app)
 {
     /** @var $schema MySqlSchemaManager */
     $schema = $app['db']->getSchemaManager();
     if (!$schema->tablesExist('users')) {
         $users = new Table('users');
         $users->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
         $users->setPrimaryKey(array('id'));
         $users->addColumn('username', 'string', array('length' => 32));
         $users->addUniqueIndex(array('username'));
         $users->addColumn('password', 'string', array('length' => 255));
         $users->addColumn('roles', 'string', array('length' => 255));
         $schema->createTable($users);
         $app['db']->insert('users', array('username' => 'user', 'password' => (new MessageDigestPasswordEncoder())->encodePassword('user', ''), 'roles' => 'ROLE_USER'));
         $app['db']->insert('users', array('username' => 'admin', 'password' => (new MessageDigestPasswordEncoder())->encodePassword('admin', ''), 'roles' => 'ROLE_ADMIN'));
     }
     return 'Done!';
 }
 /**
  * Defines the table at the specified version
  * 
  * @param Table  $table   Table
  * @param string $version Version
  */
 public function define(Table $table, $version)
 {
     switch (true) {
         // Version 0.1.0
         case version_compare($version, "0.1.0", '>='):
             $table->addColumn('id', 'integer')->setUnsigned(true)->setNotNull(true)->setAutoIncrement(true)->setComment('Country ID (local db)');
             $table->addColumn('code', 'string')->setLength(2)->setNotNull(true)->setComment("ISO code (2 char)");
             $table->addColumn('name', 'string')->setLength(50)->setNotNull(true)->setComment("Internationally recognised name");
             $table->addColumn('domain', 'string')->setLength(2)->setNotNull(false)->setComment("Top level domain suffix");
             $table->addColumn('postal_code_format', 'string')->setLength(60)->setNotNull(false)->setComment("Postal code format");
             $table->addColumn('postal_code_regex', 'string')->setLength(180)->setNotNull(false)->setComment("Postal code regex");
             $table->addColumn('phone_prefix', 'string')->setLength(20)->setNotNull(true)->setComment("Phone number prefix");
             // Primary key
             $table->setPrimaryKey(['id'], 'PK_GeoCountry_id');
             // Unique Keys
             $table->addUniqueIndex(['code'], 'UK_GeoCountry_code');
             $table->addUniqueIndex(['name'], 'UK_GeoCountry_name');
     }
 }
Example #21
0
 public function initialize(array $options = [])
 {
     $tableName = $this->options[self::OPTION_TABLENAME];
     if (!method_exists($this->connection, 'getSchemaManager')) {
         throw new \RuntimeException('The provided connection does not support query building, please choose a different connection type ' . 'that does');
     }
     if ($this->connection->getSchemaManager()->tablesExist([$tableName])) {
         return;
     }
     $table = new Table($tableName);
     $table->addColumn('id', Type::STRING, ['length' => '36']);
     $table->addColumn('stream_id', Type::STRING, ['length' => '36']);
     $table->addColumn('sequence', Type::BIGINT);
     $table->addColumn('payload', Type::TEXT);
     $table->addColumn('emitted_at', Type::DATETIME);
     $table->setPrimaryKey(['id']);
     $table->addIndex(['stream_id']);
     $table->addUniqueIndex(['stream_id', 'sequence']);
     $this->connection->getSchemaManager()->createTable($table);
 }
 /**
  * @param  string  $model
  */
 private function createTable($model, array $columns)
 {
     $metadata = Metadata::get($model);
     // Give the model a chance to modify the table for itself
     $table = new Table($metadata['orm:table']);
     foreach ($columns as $name => $options) {
         // Allow passing a type alone
         if (is_string($options)) {
             $options = ['type' => $options];
         }
         // Extract the type out of the options.
         $type = $options['type'];
         unset($options['type']);
         $column = $table->addColumn($name, $type, $options);
         if (!empty($options['primary'])) {
             $table->setPrimaryKey([$name]);
         }
     }
     // Now that the model has run its callback, create the table.
     $metadata['orm:connection']->getSchemaManager()->createTable($table);
 }
 protected function setUp()
 {
     $this->connection = DbalConnection::fromConfiguration(['driver' => 'pdo_sqlite', 'memory' => true, 'dbname' => 'test_db']);
     $testDataTable = new Table("test_data");
     $testDataTable->addColumn("name", "string");
     $testDataTable->addColumn("age", "integer");
     $testDataTable->addColumn("created_at", "datetime");
     $testDataTable->addColumn("price", "float");
     $testDataTable->addColumn("active", "boolean");
     $testDataTable->setPrimaryKey(["name"]);
     $this->connection->connection()->getSchemaManager()->createTable($testDataTable);
     $this->dataTypeLocation = ApplicationDataTypeLocation::fromPath(sys_get_temp_dir());
     $this->commandBus = new CommandBusMock();
     if (!is_dir(sys_get_temp_dir() . "/SqlConnector")) {
         mkdir(sys_get_temp_dir() . "/SqlConnector");
         mkdir(sys_get_temp_dir() . "/SqlConnector/DataType");
     }
     $connections = new DbalConnectionCollection();
     $connections->add($this->connection);
     $this->tableConnectorGenerator = new TableConnectorGenerator($connections, $this->dataTypeLocation, ConfigLocation::fromPath(sys_get_temp_dir()), $this->commandBus, Bootstrap::getServiceManager()->get("config")['prooph.link.sqlconnector']['doctrine_processing_type_map']);
 }
Example #24
0
 /**
  * @param \TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateIndexDefinitionItem $item
  * @return \Doctrine\DBAL\Schema\Index
  * @throws \Doctrine\DBAL\Schema\SchemaException
  * @throws \InvalidArgumentException
  */
 protected function addIndex(CreateIndexDefinitionItem $item) : Index
 {
     $indexName = $item->indexName->getQuotedName();
     $columnNames = array_map(function (IndexColumnName $columnName) {
         if ($columnName->length) {
             return $columnName->columnName->getQuotedName() . '(' . $columnName->length . ')';
         }
         return $columnName->columnName->getQuotedName();
     }, $item->columnNames);
     if ($item->isPrimary) {
         $this->table->setPrimaryKey($columnNames);
         $index = $this->table->getPrimaryKey();
     } else {
         $index = GeneralUtility::makeInstance(Index::class, $indexName, $columnNames, $item->isUnique, $item->isPrimary);
         if ($item->isFulltext) {
             $index->addFlag('fulltext');
         } elseif ($item->isSpatial) {
             $index->addFlag('spatial');
         }
         $this->table = GeneralUtility::makeInstance(Table::class, $this->table->getQuotedName($this->platform), $this->table->getColumns(), array_merge($this->table->getIndexes(), [strtolower($indexName) => $index]), $this->table->getForeignKeys(), 0, $this->table->getOptions());
     }
     return $index;
 }
Example #25
0
 public function resetDatabase()
 {
     $dbPath = $this->app['sqlite_path'];
     $dbDir = dirname($dbPath);
     $filesystem = new Filesystem();
     $filesystem->mkdir($dbDir);
     $filesystem->chmod($dbDir, 0777, 00, true);
     if (!is_writable($dbDir)) {
         throw new \Exception('Unable to write to ' . $dbPath);
     }
     $schemaManager = $this->getConnection()->getSchemaManager();
     $userTable = new Table('user');
     $userTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
     $userTable->setPrimaryKey(array('id'));
     $userTable->addColumn('name', 'string', array('length' => 255));
     $userTable->addUniqueIndex(array('name'));
     $userTable->addColumn('age', 'integer');
     $schemaManager->dropAndCreateTable($userTable);
     $bookTable = new Table('book');
     $bookTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
     $bookTable->setPrimaryKey(array('id'));
     $bookTable->addColumn('name', 'string', array('length' => 255));
     $bookTable->addUniqueIndex(array('name'));
     $bookTable->addColumn('userID', 'integer');
     $bookTable->addColumn('ISBN', 'integer');
     $bookTable->addForeignKeyConstraint($userTable, array('userID'), array('id'));
     $schemaManager->dropAndCreateTable($bookTable);
     $bannedTable = new Table('banned');
     $bannedTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
     $bannedTable->setPrimaryKey(array('id'));
     $bannedTable->addColumn('name', 'string', array('length' => 255));
     $bannedTable->addUniqueIndex(array('name'));
     $bannedTable->addColumn('userID', 'integer');
     $bannedTable->addColumn('ISBN', 'integer');
     $schemaManager->dropAndCreateTable($bannedTable);
 }
 /**
  * Defines the locality columns and constraints
  * 
  * @param string $locality Locality type name
  * @param Table  $table    Database table
  * @param string $version  Bundle version
  */
 protected function defineLocality($locality, Table $table, $version)
 {
     switch (true) {
         // Version 0.1.0
         case version_compare($version, "0.1.0", '>='):
             $table->addColumn('id', 'integer')->setUnsigned(true)->setNotNull(true)->setAutoIncrement(true)->setComment("{$locality} ID");
             $table->addColumn('geoname_id', 'integer')->setUnsigned(true)->setNotNull(false)->setComment('GeoNames.org ID');
             $table->addColumn('country_id', 'integer')->setUnsigned(true)->setNotNull(true)->setComment('Country (=> ' . CountryTableDefinition::NAME . '.id)');
             $table->addColumn('name_utf8', 'string')->setLength(200)->setNotNull(true)->setComment("Name (UTF-8 encoding)");
             $table->addColumn('name_ascii', 'string')->setLength(200)->setNotNull(false)->setComment("Name (ASCII encoding)");
             $table->addColumn('latitude', 'decimal')->setPrecision(9)->setScale(6)->setNotNull(false)->setComment("Latitude coordinate");
             $table->addColumn('longitude', 'decimal')->setPrecision(9)->setScale(6)->setNotNull(false)->setComment("Longitude coordinate");
             $table->addColumn('timezone_id', 'integer')->setUnsigned(true)->setNotNull(false)->setComment("Timezone");
             $table->addColumn('creation_date', 'datetime')->setNotNull(true)->setComment("Database creation date");
             $table->addColumn('modification_date', 'datetime')->setNotNull(false)->setComment("Database modification date");
             // Primary key
             $table->setPrimaryKey(['id'], "PK_Geo{$locality}_id");
             // Unique Keys
             $table->addUniqueIndex(['geoname_id'], 'UK_Geo{$locality}_geoname');
             // Foriegn keys
             $table->addNamedForeignKeyConstraint("FK_Geo{$locality}_country", CountryTableDefinition::NAME, ['country_id'], ['id']);
             $table->addNamedForeignKeyConstraint("FK_Geo{$locality}_timezone", TimezoneTableDefinition::NAME, ['timezone_id'], ['id']);
     }
 }
Example #27
0
 /**
  * Create the migration table to track migrations with.
  *
  * @return boolean Whether or not the table was created.
  */
 public function createMigrationTable()
 {
     $this->validate();
     if ($this->migrationTableCreated) {
         return false;
     }
     if (!$this->connection->getSchemaManager()->tablesExist(array($this->migrationsTableName))) {
         $columns = array('version' => new Column('version', Type::getType('string'), array('length' => 255)));
         $table = new Table($this->migrationsTableName, $columns);
         $table->setPrimaryKey(array('version'));
         $this->connection->getSchemaManager()->createTable($table);
         $this->migrationTableCreated = true;
         return true;
     }
     $this->migrationTableCreated = true;
     return false;
 }
Example #28
0
 private function setUpForeignKeyConstraintViolationExceptionTest()
 {
     $schemaManager = $this->_conn->getSchemaManager();
     $table = new Table("constraint_error_table");
     $table->addColumn('id', 'integer', array());
     $table->setPrimaryKey(array('id'));
     $owningTable = new Table("owning_table");
     $owningTable->addColumn('id', 'integer', array());
     $owningTable->addColumn('constraint_id', 'integer', array());
     $owningTable->setPrimaryKey(array('id'));
     $owningTable->addForeignKeyConstraint($table, array('constraint_id'), array('id'));
     $schemaManager->createTable($table);
     $schemaManager->createTable($owningTable);
 }
 /**
  * @group DBAL-105
  */
 public function testDiff()
 {
     $table = new \Doctrine\DBAL\Schema\Table('twitter_users');
     $table->addColumn('id', 'integer', array('autoincrement' => true));
     $table->addColumn('twitterId', 'integer', array('nullable' => false));
     $table->addColumn('displayName', 'string', array('nullable' => false));
     $table->setPrimaryKey(array('id'));
     $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
     $newtable->addColumn('id', 'integer', array('autoincrement' => true));
     $newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
     $newtable->addColumn('display_name', 'string', array('nullable' => false));
     $newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
     $newtable->setPrimaryKey(array('id'));
     $c = new Comparator();
     $tableDiff = $c->diffTable($table, $newtable);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
     $this->assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns));
     $this->assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns));
     $this->assertEquals(0, count($tableDiff->removedColumns));
 }
Example #30
0
 public function testSyntaxErrorException()
 {
     $table = new \Doctrine\DBAL\Schema\Table("syntax_error_table");
     $table->addColumn('id', 'integer', array());
     $table->setPrimaryKey(array('id'));
     foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
         $this->_conn->executeQuery($sql);
     }
     $sql = 'SELECT id FRO syntax_error_table';
     $this->setExpectedException('\\Doctrine\\DBAL\\Exception\\SyntaxErrorException');
     $this->_conn->executeQuery($sql);
 }