使用flyway命令行版本索引

时间:2019-07-04 17:36:01

标签: java sql-server migration flyway

这是我的情况,我是DBA,并且接受了使用CI创建位桶重新发布的任务,以控制SQL Server中的所有过程和功能。 第一步已经通过5.2.4版的飞行路线成功地完成,重复脚本可重复。

现在我正在尝试扩展项目以仅控制索引。

某些项目实现了飞行路线或其他迁移解决方案,而有些则没有实现。所以我想控制这个项目中的索引。

我的问题是有可能,飞行路线文档尚不清楚,我也尝试使用NTV__脚本,但不起作用。

以前有人尝试过吗?我在问一些不可能的事情吗?

conf file

flyway.url=jdbc:sqlserver://select:1433;databaseName=database
flyway.user=sa
flyway.password=pass
flyway.locations=filesystem:/home/krismorte/repo/DOCKER/flyway-teste/
flyway.sqlMigrationSuffixes=.sql
flyway.table=flyway_my_sql_objects
flyway.baselineOnMigrate=true
flyway.allowMixedMigrations = true

可重复文件

CREATE OR ALTER PROCEDURE [DBA].[USP_UPDATESTATISTICS] @RUN INT = 0
--  WITH ENCRYPTION
AS
BEGIN

SET NOCOUNT ON;

DECLARE 
    @TOP                INT = 200,              -- QUANTOS INDEXES SERÃO EFETUADOS O REBUILD POR VEZ
    @WINDOW_LIMIT       DATETIME = '06:00:00',  -- VALOR DO HORÁRIO LIMITE DA JANELA EX: '13:32:00'
    @STR_UPDATESTATS    NVARCHAR(MAX) = '',
    @ID                 INT,
    @TIME               DATETIME

SELECT TOP (@TOP)
     ID = IDENTITY(INT, 1, 1)
    ,DATABASENAME = DB_NAME()
    ,TABLENAME = O.NAME
INTO #STATISTICSTOUPDATE
FROM SYS.OBJECTS O
WHERE OBJECTPROPERTY(O.[OBJECT_ID], 'ISMSSHIPPED') = 0
    AND O.TYPE_DESC = 'USER_TABLE'
ORDER BY [TABLENAME]  DESC

WHILE EXISTS(SELECT TOP 1 1 FROM #STATISTICSTOUPDATE)
BEGIN   
    SELECT TOP 1 
        @ID = ID,
        @TIME = CONVERT(VARCHAR(8),DATEADD(HOUR, -3, GETDATE()),108) ,
        @STR_UPDATESTATS = '
        SET ANSI_PADDING ON;
        UPDATE STATISTICS [' + I.TABLENAME + '] WITH FULLSCAN;
        SET ANSI_PADDING OFF;' 
    FROM #STATISTICSTOUPDATE I;     

    IF (@WINDOW_LIMIT IS NULL OR @TIME < @WINDOW_LIMIT)
    BEGIN
        BEGIN TRY
            PRINT 'EXECUTANDO: ' + @STR_UPDATESTATS + CHAR(13) + CHAR(10);  

            IF @RUN = 1
             EXEC (@STR_UPDATESTATS);   

            INSERT INTO [DBA].[LOGUPDATESTATISTICS] ([DATA], [DATABASE], [TABLE_NAME], [SCRIPT_REBUILD], [STATUS]) 
            SELECT @TIME, I.DATABASENAME, I.TABLENAME, @STR_UPDATESTATS, 'OK' FROM #STATISTICSTOUPDATE I WHERE ID = @ID;    
        END TRY
        BEGIN CATCH
            INSERT INTO [DBA].[LOGUPDATESTATISTICS] ([DATA], [DATABASE], [TABLE_NAME], [SCRIPT_REBUILD], [STATUS], [ERROR_MESSAGE]) 
            SELECT @TIME, I.DATABASENAME, I.TABLENAME, @STR_UPDATESTATS, 'OK', ERROR_MESSAGE() FROM #STATISTICSTOUPDATE I WHERE ID = @ID;
        END CATCH
    END
    DELETE FROM #STATISTICSTOUPDATE WHERE ID = @ID;
END


DROP TABLE #STATISTICSTOUPDATE;
END
GO

没有TYransaction文件

create index ix_teste on [DBO].Table_EXTRACAO_10 (marketplace);

repeatable可以正常工作,但no native不能,我已经尝试过将名称更改为V _

0 个答案:

没有答案