Microsoft Sync Framework - How to reprovision a table (or entire scope) after schema changes?

后端 未结 4 1412
遇见更好的自我
遇见更好的自我 2021-01-21 04:30

I have already setup syncing with Microsoft Sync Framework, and now I need to add fields to a table. How do I re-provision the databases?

The setup is exceedingly simple

4条回答
  •  感情败类
    2021-01-21 04:45

    You can use this script:

    declare @SQL varchar(max);
    set @SQL='';
    select @SQL += ' IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[schema_info]'') AND type in (N''U'')) ' +  
                   ' DROP TABLE [dbo].[schema_info]; ' +
                   ' IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[scope_config]'') AND type in (N''U'')) ' + 
                   ' DROP TABLE [dbo].[scope_config]; ' +
                   ' IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[scope_info]'') AND type in (N''U'')) ' + 
                   ' DROP TABLE [dbo].[scope_info]; ' +
                   ' IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' +  name  + '_tracking]'') AND type in (N''U'')) ' + 
                   ' DROP TABLE [dbo].[' +  name  + '_tracking]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_delete_trigger]'')) ' +
                   ' DROP TRIGGER [dbo].[' + name + '_delete_trigger];' +
                   ' IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_insert_trigger]'')) ' +
                   ' DROP TRIGGER [dbo].[' + name + '_insert_trigger]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_update_trigger]'')) ' +
                   ' DROP TRIGGER [dbo].[' + name + '_update_trigger]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_delete]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_delete]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_deletemetadata]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_deletemetadata]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_insert]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_insert]; ' + 
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_insertmetadata]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_insertmetadata]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_selectchanges]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_selectchanges]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_selectrow]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_selectrow]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_update]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_update]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_updatemetadata]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_updatemetadata]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_BulkType]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_BulkType]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_bulkinsert]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_bulkinsert]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_bulkupdate]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_bulkupdate]; ' +
                   ' IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[' + name + '_bulkdelete]'') AND type in (N''P'', N''PC'')) ' +
                   ' DROP PROCEDURE [dbo].[' + name + '_bulkdelete]; '              
    from sysobjects
    where type = 'U'
    
    --select @SQL
    EXEC(@SQL)
    GO
    

提交回复
热议问题