Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading databases for each multisite #1227

Closed
cosmicdreams opened this issue Mar 20, 2017 · 6 comments
Closed

Loading databases for each multisite #1227

cosmicdreams opened this issue Mar 20, 2017 · 6 comments
Assignees
Labels
Enhancement A feature or feature request

Comments

@cosmicdreams
Copy link

Hi all, really inspired by all the work going in here to support multisite configurations.

I was wondering if @danepowell could give guidance / documentation on how to load a database per site within the multisite. Perhaps this config has not been included yet because not every multisite will need to load a database per site during local:sync. But I do.

@cosmicdreams
Copy link
Author

cosmicdreams commented Mar 20, 2017

Ah I think I'm starting to see why this support isn't available yet:

Ideally we would want to execute a local:sync like command for each of the sites within the multisite. This command accept two inputs for the remote and local databases. It would be really nice to use the foreach phing statement to loop over a list of sites to execute this command.

However:

  1. Phing's foreach doesn't allow multiple parameters, so we wouldn't be able to pass specific remote and local targets.
  2. We would need to add config to project.yml to support the remote and local alias declarations, but use some kind of associative array so that the remote and local are passed together.
  3. Maybe have to add new phing "target"s so that the foreach statement can use them.

2 and 3 can be solved but 1 cannot (until phing 3 is out, stable, and supported by blt).

Without 1 we're left with requiring the developer copy / paste sample code into a project.local.yml to override local:sync to support multisite.

@danepowell am I missing something with that analysis?

@cosmicdreams
Copy link
Author

Oh wow, don't know how I missed this but there's a example.multsite.yml that I didn't find in the documentation that declares a ${project.cloud_alias} that seems really useful. But it doesn't appear to be used in anywhere. Specifically it does seem to be used in local:sync at all.

@cosmicdreams
Copy link
Author

cosmicdreams commented Mar 21, 2017

OHEY I think I figured this out using Phing 2:

My build.xml:

<!-- Override local:sync to support multisite configurations. -->
  <target name="local:sync" description="Synchronize local environment from remote (remote --> local)."
          depends="setup:drupal:settings">
    <foreach list="${multisite.aliases.name}" param="multisite.aliases.name" target="local:sync:multisite"/>
  </target>

  <target name="local:sync:multisite" description="Synchronize local environment from remote (remote --> local) for the multisite."
          depends="setup:drupal:settings">
    <drush command="cc drush"/>
    <drush command="sql-drop"/>
    <if>
      <equals arg1="${drush.sanitize}" arg2="true"/>
      <then>
        <drush command="sql-sync" alias="">
          <option name="structure-tables-key">lightweight</option>
          <option name="create-db"/>
          <option name="sanitize"/>
          <param>@${project.cloud_alias}.${multisite.aliases.name}.${multisite.aliases.suffix.remote}</param>
          <param>@${project.cloud_alias}.${multisite.aliases.name}.${multisite.aliases.suffix.local}</param>
        </drush>
      </then>
      <else>
        <drush command="sql-sync" alias="">
          <option name="structure-tables-key">lightweight</option>
          <option name="create-db"/>
          <param>@${project.cloud_alias}.${multisite.aliases.name}.${multisite.aliases.suffix.remote}</param>
          <param>@${project.cloud_alias}.${multisite.aliases.name}.${multisite.aliases.suffix.local}</param>
        </drush>
      </else>
    </if>

    <drush command="cache-clear">
      <param>drush</param>
    </drush>
    <drush command="cache-rebuild"/>
  </target>

In my project.yml, I added:

project.cloud_alias: @my_multisite
multisite
  aliases:
    suffix:
      local: 'local'
      remote: 'test'
    name:
      - site1
      - site2
      - site3

Where site1, site2, site3, where proper parts of a drush alias that looks like @my_multisite.site1.test that points to the staging version of the remote site.

Oh, and I also setup proper drush aliases for each of these remote sites so that they work. I haven't tested this yet, that comes next. Just got excited about how this solution works around the "need multiple parameters for the foreach to work" problem.

@bobbygryzynger
Copy link
Contributor

bobbygryzynger commented Mar 21, 2017

@cosmicdreams - take a look at multisite.md. It describes how you can sync site-specific databases.

@cosmicdreams
Copy link
Author

Hi @bobbygryzynger I have. And that's how I got this far. And ... Oh there's documentation here I haven't seen before.

Yes, the use of site.yml would improve / reduce the complexity of handling the proper config. However, the documentation doesn't seem to cover how to get local:refresh to refresh all of the sites of the multisite.

I guess if I want that I could still use the foreach above, but without the extra config that duplicates what site.yml does more efficiently

grasmash added a commit to grasmash/bolt that referenced this issue Mar 21, 2017
@grasmash grasmash self-assigned this Mar 21, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Mar 21, 2017
@danepowell
Copy link
Contributor

Right now, I think BLT + DrupalVM only support a single site at a time, and the related BLT aliases (i.e. local:sync and local:refresh) are designed to take a single site alias as a parameter. So the idea is that you can sync down any one database from a multisite at a time. But you couldn't, for instance, sync every single database down simultaneously and view them all on independent URLs from within the same VM.

However it looks like @grasmash might be working to change that 😄

@grasmash grasmash added the Enhancement A feature or feature request label Apr 3, 2017
grasmash added a commit that referenced this issue Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A feature or feature request
Projects
None yet
Development

No branches or pull requests

4 participants