Skip to content

Commit

Permalink
fix(dev-env): SQL sync for single sites
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Nov 18, 2024
1 parent 84ae76d commit d050084
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/commands/dev-env-sync-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ export class DevEnvSyncSQLCommand {
return;
}

const prologue = `
DELIMITER $$
CREATE PROCEDURE update_blog_domains()
BEGIN
IF EXISTS (SELECT * FROM information_schema.tables WHERE table_schema = 'wordpress' AND table_name = 'wp_blogs') THEN
`;
const epilogue = `
END IF;
END$$
DELIMITER ;
CALL update_blog_domains();
`;

const queries: string[] = [];
for ( const site of networkSites ) {
if ( ! site?.blogId || ! site?.homeUrl ) {
Expand All @@ -264,12 +277,15 @@ export class DevEnvSyncSQLCommand {
: this.landoDomain;

queries.push(
`UPDATE wp_blogs SET domain = '${ newDomain }' WHERE blog_id = ${ Number( site.blogId ) };`
` UPDATE wp_blogs SET domain = '${ newDomain }' WHERE blog_id = ${ Number(
site.blogId
) };`
);
}

if ( queries.length ) {
await fs.promises.appendFile( this.sqlFile, queries.join( '\n' ) );
const sql = `${ prologue }\n${ queries.join( '\n' ) }\n${ epilogue }`;
await fs.promises.appendFile( this.sqlFile, sql );
}
}

Expand Down

0 comments on commit d050084

Please sign in to comment.