MySQLPrecreated db implementation which does not require admin rights

Thanks for the pointers!  I'll give it a shot.

The goal is definitely to provision 3 separate databases, cos there issues
around cross-db transactions and switching, which we'd like to catch in
testing.  Having 1 db would be good enough for the rough draft, but I'll
go for the 3 if I can manage it.

On Mon, Sep 08, 2014 at 03:35:59PM -0700, Tim Otten wrote:
> > +  }
> > +
> > +  /**
> > +   * Create a datasource representing a new user and database
> > +   *
> > +   * @param string $hint an advisory string; ideally included in $db/$user
> > +   * @return Datasource;
> > +   */
> > +  public function createDatasource($hint) {
> > +    $dsnPattern = getenv('PRECREATED_DSN_PATTERN');
> > +
> > +    if ( empty( $dsnPattern ) ) {
> > +        throw new Exception('Must set PRECREATED_DSN_PATTERN to use MySQLPrecreated.');
> > +    }
> > +    $dsn = str_replace('{{db_seq}}', self::$db_seq++, $dsnPattern);
> > +
> 
> So one possible way to address this is to simply store db_seq in the ConfigRepository. However,  different threads may have different PRECREATED_DSN_PATTERN values, you'd need to store separate db_seq's for each pattern, and I can think of a few ways in which storing the valuing will have weird affects.
> 
> So my suggestion would be to scan the DBs to see which DSN#s are actually in use:
> 
> ```php
> if ($dsnPattern contains "{{db_seq}}") {
>   do {
>     $dsn = str_replace('{{db_seq}}', self::$db_seq++, $dsnPattern);
>     $isNumTaken = false; // does another existing DB use this data-source?
>     // FIXME: $this->instances should an injected reference to InstanceRepository
>     foreach ($this->instances->findAll() as $instance) {
>       /** @var Instance $instance */
>       if ($instance->getDatasource()->toCiviDSN() === $dsn) {
>           $isNumTaken = true;
>           break;
>       }
>     }
>   } while ($isNumtaken);
> }
> ```
> 
> Of course... since your current goal is to support a single, hard-coded DB anyway, we could just comment-out the $db_seq stuff and focus on testing other aspects of the build?
> 
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/totten/amp/pull/18/files#r17272057