Skip to content

7.x - Add ability to load squashed tenant schema from SQL file#1

Open
jackhealy1 wants to merge 3 commits into
6.xfrom
7.x
Open

7.x - Add ability to load squashed tenant schema from SQL file#1
jackhealy1 wants to merge 3 commits into
6.xfrom
7.x

Conversation

@jackhealy1

Copy link
Copy Markdown

Title: feat: Add ability to load squashed tenant schema from SQL file

Description:

This pull request introduces a new feature that allows for a squashed database schema of a tenant to be loaded from a
single "squashed" SQL file. This is particularly useful for applications with a large number of migrations, as it can
significantly speed up the tenant setup process.

Key Changes:

  1. New Configuration Option:

    • A new configuration option, tenancy.db.tenant-squashed-sql-path, is introduced. This can be set in the
      config/tenancy.php file.
  2. Updated Database Creation Logic:

    • The MariaDB database driver, used for MySQL/MariaDB connections, has been modified.
    • Immediately after a new tenant database is created, the system checks for the tenant-squashed-sql-path configuration.
  3. SQL Import Process:

    • If the specified .sql file exists, its contents are executed against the new tenant database.
    • This import happens before any standard tenant migrations are run.
  4. Robustness and Error Handling:

    • Optional Feature: If the path is not configured or the file doesn't exist, this step is silently and safely skipped.
    • Error Logging: The process is wrapped in a try...catch block. If the SQL file contains errors, the exception is logged,
      and the tenant creation process is halted to prevent a corrupt installation.
    • Success Logging: A success message is logged when the file is imported correctly.

How to Use:

  1. Add the tenant-squashed-sql-path key to the db array in your config/tenancy.php file.
  2. Set its value to the absolute path of your squashed schema file (e.g., database_path('schema/tenant-schema.sql')).

Comment thread assets/configs/tenancy.php
Comment thread src/Generators/Webserver/Database/Drivers/MariaDB.php Outdated
Comment thread src/Generators/Webserver/Database/Drivers/MariaDB.php

@rayblair06 rayblair06 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants