Create database using doctrine schema tool
338422
private function createDatabase()
    {
        $em       = $this->entityManager;
        $metadata = $em->getMetadataFactory()->getAllMetadata();

        $schemaTool = new SchemaTool($em);
        $schemaTool->createSchema($metadata);
    }
1147546
public function createSchema($outputPathAndFilename = null)
    {
        $schemaTool = new SchemaTool($this->entityManager);
        $allMetaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
        if ($outputPathAndFilename === null) {
            $schemaTool->createSchema($allMetaData);
        } else {
            $createSchemaSqlStatements = $schemaTool->getCreateSchemaSql($allMetaData);
            file_put_contents($outputPathAndFilename, implode(PHP_EOL, $createSchemaSqlStatements));
        }
    }
39799
public function createSchema()
    {
        $query = 'CREATE TABLE IF NOT EXISTS `'.self::LIST_COLLECTION_TABLE_NAME.'` (
          `id` int NOT NULL AUTO_INCREMENT,
          `uuid` varchar(255) UNIQUE NOT NULL,
          `headers` text DEFAULT NULL,
          `created_at` TIMESTAMP NOT NULL,
          `updated_at` TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW(),
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;';

        $this->pdo->exec($query);

        $query2 = 'CREATE TABLE IF NOT EXISTS `'.self::LIST_ELEMENT_TABLE_NAME.'` (
          `id` int NOT NULL AUTO_INCREMENT,
          `uuid` varchar(255) NOT NULL,
          `list` varchar(255) NOT NULL,
          `body` text DEFAULT NULL,
          `created_at` TIMESTAMP NOT NULL,
          `updated_at` TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW(),
          PRIMARY KEY (`id`),
          CONSTRAINT `list_foreign_key` FOREIGN KEY (`list`) REFERENCES `'.self::LIST_COLLECTION_TABLE_NAME.'`(`uuid`) ON UPDATE CASCADE ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;';

        $this->pdo->exec($query2);
    }
707651
public function runSetup()
    {
        if ($this->params->forceIsActive) {
            $this->consoleWriteLineWithIndent('Force mode active! Database will be generated', Color::YELLOW);
            
            $dbParams          = $this->getDbConnectionParams();    
            $dbConnectionCmd   = $this->getDbConnectionCmd();
            $dropDatabaseCmd   = $dbConnectionCmd . ' -e"DROP DATABASE ' . $dbParams['dbname'] . ';"';
            $createDatabaseCmd = $dbConnectionCmd . ' -e"CREATE DATABASE ' . $dbParams['dbname'] . ';"';
            $createSchemaCmd   = 'php bin/doctrine.php orm:schema-tool:create';
            
            $this->consoleWriteWithIndent('Dropping database... ');
            $output = shell_exec($dropDatabaseCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
            
            $this->consoleWriteWithIndent('Creating database... ');
            $output = shell_exec($createDatabaseCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
            
            $this->consoleWriteWithIndent('Creating tables... ');
            $output = shell_exec($createSchemaCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
        } else {
            $this->consoleWriteLineWithIndent('Nothing to do. For database generating please use --force|-f option.', Color::YELLOW);
        }
    }
283016
def setup():
    
    try:
        db.bind(**config.database_config)
    except OSError:
        # Attempted to connect to a file-based database where the file didn't
        # exist
        db.bind(**config.database_config, create_db=True)

    rebuild = True

    try:
        db.generate_mapping(create_tables=True)
        with orm.db_session:
            version = GlobalConfig.get(key='schema_version')
            if version and version.int_value != SCHEMA_VERSION:
                logger.info("Existing database has schema version %d",
                            version.int_value)
            else:
                rebuild = False
    except:  # pylint:disable=bare-except
        logger.exception("Error mapping schema")

    if rebuild:
        logger.info("Rebuilding schema")
        try:
            db.drop_all_tables(with_all_data=True)
            db.create_tables()
        except:
            raise RuntimeError("Unable to upgrade schema automatically; please " +
                               "delete the existing database and try again.")

    with orm.db_session:
        if not GlobalConfig.get(key='schema_version'):
            logger.info("setting schema version to %d", SCHEMA_VERSION)
            GlobalConfig(key='schema_version',
                         int_value=SCHEMA_VERSION)
            orm.commit()
351338
def create_database(self, instance, name, character_set=None,
            collate=None):
        """"""
        return instance.create_database(name, character_set=character_set,
                collate=collate)
7657
public function createBundlesSchema()
    {
        foreach ($this->_application->getBundles() as $bundle) {
            $this->createBundleSchema($bundle->getId());
        }
    }
776397
private static void generateSchema(SQLiteDatabaseSchema schema) throws FileNotFoundException, IOException {
		// when we run in JUNIT of Kripton, we don't have to generate schemas
		// if (BindDataSourceSubProcessor.JUNIT_TEST_MODE)
		// return;
		if (!schema.generateSchema)
			return;

		// and now, write schema.create.v and schema.drop.v
		String schemaCreation = defineFileName(schema);

		String schemaLocation = KriptonOptions.getSchemaLocation();

		File schemaCreatePath = new File(schemaLocation).getAbsoluteFile();
		File schemaCreateFile = new File(schemaLocation, schemaCreation).getAbsoluteFile();
		schemaCreatePath.mkdirs();

		AnnotationProcessorUtilis.infoOnGeneratedFile(BindDataSource.class, schemaCreateFile);
		FileOutputStream fos = new FileOutputStream(schemaCreateFile);
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

		bw.write("------------------------------------------------------------------------------------\n");
		bw.write("--\n");
		bw.write("-- Filename: " + schemaCreation + "\n");
		bw.write("--\n");
		bw.write(String.format("-- Date: %s", (new Date()).toString()) + "\n");
		bw.write("--\n");
		if (!BindDataSourceSubProcessor.JUNIT_TEST_MODE) {
			bw.write(String.format("-- This file was generated by Kripton Annotation Processor v. %s\n",
					Version.getVersion()));
			bw.write(String.format("--\n"));
		}
		bw.write("------------------------------------------------------------------------------------\n");
		bw.newLine();
		for (String sql : schema.sqlForCreate) {
			bw.write(sql);
			bw.newLine();
		}
		bw.close();
	}
403497
def create_db():
    
    from flask_appbuilder.models.sqla import Model

    engine = current_app.appbuilder.get_session.get_bind(mapper=None, clause=None)
    Model.metadata.create_all(engine)
    click.echo(click.style("DB objects created", fg="green"))
1285024
def create_schema(db):
    """"""
    schema_dir = pkg_resources.resource_filename('git_code_debt', 'schema')
    schema_files = os.listdir(schema_dir)

    for sql_file in schema_files:
        resource_filename = os.path.join(schema_dir, sql_file)
        with open(resource_filename, 'r') as resource:
            db.executescript(resource.read())
695612
protected function _createdb($check = false) {
		$this->out(__d('cake_installer', 'Creating database and initializing data'));
		$this->hr();

		$resultCheck = $this->InstallerCheck->checkDbTableExists();
		if ($resultCheck) {
			if ($check) {
				$this->out('<success>' . __d('cake_installer', 'This action has already been successfully completed. Skipped.') . '</success>');

				return true;
			} elseif ($this->useActionNotify) {
				if (!$this->_checkSure(__d('cake_installer', 'All schemas exists. Re-create?'))) {
					return true;
				}
			}
		}

		$this->out(__d('cake_installer', 'Create schema of application'));
		$this->hr();
		$yesArg = '';
		if (!empty($this->param('yes'))) {
			$yesArg = ' --yes';
		}
		$defaultSchemaArgs = 'schema create --quiet' . $yesArg;
		$this->dispatchShell($defaultSchemaArgs);
		$this->hr();
		$this->nl(1);
		$schemaList = $this->ConfigInstaller->getListSchemaCreation();
		if (empty($schemaList)) {
			return true;
		}

		$this->out(__d('cake_installer', 'Create additional schemes'));
		foreach ($schemaList as $schemaName) {
			if (empty($schemaName)) {
				continue;
			}

			$this->hr();
			$this->out(__d('cake_installer', 'Create additional scheme: \'%s\'', $schemaName));
			$this->hr();
			$this->nl(1);
			$additionalSchemaArgs = 'schema create ' . $schemaName . ' --quiet' . $yesArg;
			$this->dispatchShell($additionalSchemaArgs);
		}
		$this->hr();
		$this->out('<info>' . __d('cake_installer', 'Creating additional schemes completed.') . '</info>');

		return true;
	}
92018
def create_database_files
      username = builder.options['database-username']
      password = builder.options['database-password']

      builder.remove_file "config/database.yml"
      create_database_yml_file("config/database.sample.yml", "username", "pass")
      create_database_yml_file("config/database.yml", username, password)
    end
767621
protected function createSqlDbMap()
    {
        if ($this->getSqlDbMap() === null) {
            return;
        }

        // Produce the sql -> database map
        $sqldbmap = new Properties();

        // Check to see if the sqldbmap has already been created.
        if ($this->getSqlDbMap()->exists()) {
            $sqldbmap->load($this->getSqlDbMap());
        }

        if ($this->packageObjectModel) {
            // in this case we'll get the sql file name from the package attribute
            $dataModels = $this->packageDataModels();
            foreach ($dataModels as $package => $dataModel) {
                foreach ($dataModel->getDatabases() as $database) {
                    $name = ($package ? $package . '.' : '') . 'schema.xml';
                    $sqlFile = $this->getMappedFile($name);
                    $sqldbmap->setProperty($sqlFile->getName(), $database->getName());
                }
            }
        } else {
            // the traditional way is to map the schema.xml filenames
            $dmMap = $this->getDataModelDbMap();
            foreach (array_keys($dmMap) as $dataModelName) {
                $sqlFile = $this->getMappedFile($dataModelName);
                if ($this->getDatabase() === null) {
                    $databaseName = $dmMap[$dataModelName];
                } else {
                    $databaseName = $this->getDatabase();
                }
                $sqldbmap->setProperty($sqlFile->getName(), $databaseName);
            }
        }

        try {
            $sqldbmap->store($this->getSqlDbMap(), "Sqlfile -> Database map");
        } catch (IOException $e) {
            throw new IOException("Unable to store properties: " . $e->getMessage());
        }
    }
121888
private function setup()
    {
        $manager = $this->getConnection()->getSchemaManager();
        if ($this->tablesExist === true || $manager->tablesExist([$this->options['db_table']]) === true) {
            $this->tablesExist = true;

            return;
        }

        $schema = new Schema();
        $table = $schema->createTable($this->options['db_table']);

        $table->addColumn($this->options['db_column_feature'], 'string', ['length' => 255]);
        $table->addColumn($this->options['db_column_state'], 'boolean');

        $table->setPrimaryKey([$this->options['db_column_feature']]);

        $platform = $this->getConnection()->getDatabasePlatform();
        $queries = $schema->toSql($platform);

        foreach ($queries as $query) {
            $this->getConnection()->executeQuery($query);
        }

        $this->tablesExist = true;
    }
936559
public function compile()
    {
        // "driver" is used only for Doctrine, thus we (mis-)use it here
        // additionally, when no path is set, skip this step, assuming no DB is needed
        if ($this->settings['backendOptions']['driver'] !== null && $this->settings['backendOptions']['path'] !== null) {
            $schemaTool = new SchemaTool($this->entityManager);
            if ($this->settings['backendOptions']['driver'] === 'pdo_sqlite') {
                $schemaTool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
            } else {
                $schemaTool->updateSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
            }

            $proxyFactory = $this->entityManager->getProxyFactory();
            $proxyFactory->generateProxyClasses($this->entityManager->getMetadataFactory()->getAllMetadata());

            $this->logger->info('Doctrine 2 setup finished', LogEnvironment::fromMethodName(__METHOD__));
            return true;
        } else {
            $this->logger->notice('Doctrine 2 setup skipped, driver and path backend options not set!');
            return false;
        }
    }
659178
def create_schema(self):
        """"""
        cursor = self.cursor
        execute = cursor.execute
        execute('SHOW TABLES')
        tables = {table for table, in cursor}
        if 'gauged_data' not in tables:
            execute("""CREATE TABLE gauged_data (
                namespace INT(11) UNSIGNED NOT NULL,
                offset INT(11) UNSIGNED NOT NULL,
                `key` BIGINT(15) UNSIGNED NOT NULL,
                data MEDIUMBLOB NOT NULL,
                flags INT(11) UNSIGNED NOT NULL,
                PRIMARY KEY (offset, namespace, `key`))""")
        if 'gauged_keys' not in tables:
            execute("""CREATE TABLE gauged_keys (
                id BIGINT(15) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
                namespace INT(11) UNSIGNED NOT NULL,
                `key` VARCHAR(255) BINARY NOT NULL,
                UNIQUE KEY (namespace, `key`))""")
        if 'gauged_writer_history' not in tables:
            execute("""CREATE TABLE gauged_writer_history (
                id VARCHAR(255) NOT NULL PRIMARY KEY,
                timestamp BIGINT(15) UNSIGNED NOT NULL)""")
        if 'gauged_cache' not in tables:
            execute("""CREATE TABLE gauged_cache (
                namespace INT(11) UNSIGNED NOT NULL,
                `key` BIGINT(15) UNSIGNED NOT NULL,
                hash BINARY(20) NOT NULL,
                length BIGINT(15) UNSIGNED NOT NULL,
                start BIGINT(15) UNSIGNED NOT NULL,
                value FLOAT(11),
                PRIMARY KEY (namespace, hash, length, start))""")
        if 'gauged_statistics' not in tables:
            execute("""CREATE TABLE gauged_statistics (
                namespace INT(11) UNSIGNED NOT NULL,
                offset INT(11) UNSIGNED NOT NULL,
                data_points INT(11) UNSIGNED NOT NULL,
                byte_count INT(11) UNSIGNED NOT NULL,
                PRIMARY KEY (namespace, offset))""")
        if 'gauged_metadata' not in tables:
            execute("""CREATE TABLE gauged_metadata (
                `key` VARCHAR(255) NOT NULL PRIMARY KEY,
                value VARCHAR(255) NOT NULL)""")
        self.db.commit()
785884
public function createSchema($schemaName = 'public')
    {
        $sql = \sprintf('CREATE SCHEMA %s;',
            $this->quoteSchemaName($schemaName)); // from postgres 9.3 we can use "CREATE SCHEMA IF NOT EXISTS schema_name"
        $this->execute($sql);
    }