Ticket #848 (closed task: fixed)

Opened 16 months ago

Last modified 16 months ago

Postgres DROP/CREATE DATABASE in sfDoctrinePlugin

Reported by: tigglet Owned by: jwage
Priority: minor Milestone: 0.10.3
Component: Other Version: 0.10.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description (last modified by tigglet) (diff)

In order to drop or create a database, you'll need to connect to a database other than your target database. Both the "postgres" database and the "template1" databases are present in nearly all installations of Postgres by default so it'd be safe to assume one or the other exists. Recommend we use "postgres".

Change History

Changed 16 months ago by tigglet

Just tested. You can create/drop a database if you connect without specifying a database of any sort.

Changed 16 months ago by tigglet

  • description modified (diff)

I was a little too hasty with my response.

You can connect without specifying a database but postgres will assume that the name of the user is the name of the database you want to connect to. Here's my test code:

<?php

	$dbh = new PDO('pgsql:host=localhost port=5432 user=postgres');
	//$dbh->exec('CREATE DATABASE testdb');
	$dbh->exec('DROP DATABASE testdb');

?>

This worked because there was a db of the same name as the user (user = "postgres", database named "postgres" existed). It does NOT work if there is no database of the same name as the user, which puts us right back where we started. So, you'd need to connect to database "postgres" or "template1" using the supplied username. I recommend "postgres".

Changed 16 months ago by jwage

  • milestone changed from 0.10.4 to 0.10.3

Changed 16 months ago by jwage

Hmm, I don't like the fact that we have to connect to a different database name in order to drop/create databases. I was hoping that all databases supported making a generic connection without specifying a database and would allow me to issue drop/create database statements with that tmp connection. This works for mysql, but obviously not pgsql. I am getting pgsql setup so I can test this. I guess we'll have to have some kind of map for driver => 'tmp_db_name', so we can connect to that database if a mapping exists.

Changed 16 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [3967]) fixes #848

Note: See TracTickets for help on using tickets.