Skip to content

Instantly share code, notes, and snippets.

@saurabhnanda
Created Sep 9, 2020
Embed
What would you like to do?
/*------------------------------------------------------------------------------
* ML Install Script generated 2020-09-09 07:07:59 for SQL Anywhere (Consolidated)
* by MobiLink 17 Plug-in
*-----------------------------------------------------------------------------*/
CALL ml_model_begin_install( 'v2' )
GO
/*------------------------------------------------------------------------------
* Creating schema related to the table 'master.projects'.
*-----------------------------------------------------------------------------*/
/* Create the shadow delete table 'master.projects_del'. */
CALL ml_model_register_schema_use( 'v2', 'TABLE', 'master', 'projects_del', 'projects_del', '2b900745c1ae1b41e872c8abadc86f73' )
GO
IF ml_model_get_schema_action( 'v2', 'TABLE', 'master', 'projects_del', 'projects_del', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'TABLE', 'master', 'projects_del', 'projects_del' );
DROP TABLE "master"."projects_del";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'TABLE', 'master', 'projects_del', 'projects_del', 'OVERWRITE' ) = 'CREATE' THEN
CREATE TABLE "master"."projects_del" (
"id" integer not null,
"last_modified" TIMESTAMP DEFAULT CURRENT TIMESTAMP,
PRIMARY KEY ("id")
);
CALL ml_model_register_schema( 'TABLE', 'master', 'projects_del', 'projects_del', 'DROP TABLE "master"."projects_del"', '2b900745c1ae1b41e872c8abadc86f73', 0 );
END IF
GO
/* Create the timestamp column 'last_modified'. */
CALL ml_model_register_schema_use( 'v2', 'COLUMN', 'master', 'projects', 'last_modified', 'fc19e404e3c4ee3d98c33cdcee75a1ca' )
GO
IF ml_model_get_schema_action( 'v2', 'COLUMN', 'master', 'projects', 'last_modified', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'COLUMN', 'master', 'projects', 'last_modified' );
ALTER TABLE "master"."projects" DROP "last_modified";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'COLUMN', 'master', 'projects', 'last_modified', 'OVERWRITE' ) = 'CREATE' THEN
ALTER TABLE "master"."projects" ADD "last_modified" TIMESTAMP NOT NULL DEFAULT TIMESTAMP;
CALL ml_model_register_schema( 'COLUMN', 'master', 'projects', 'last_modified', 'ALTER TABLE "master"."projects" DROP "last_modified"', 'fc19e404e3c4ee3d98c33cdcee75a1ca', 0 );
END IF
GO
/* Create the shadow delete trigger 'projects_ins'. */
CALL ml_model_register_schema_use( 'v2', 'TRIGGER', 'master', 'projects', 'projects_ins', '13c6af778141d9b6dfee309a67e64f6c' )
GO
IF ml_model_get_schema_action( 'v2', 'TRIGGER', 'master', 'projects', 'projects_ins', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'TRIGGER', 'master', 'projects', 'projects_ins' );
DROP TRIGGER "master"."projects"."projects_ins";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'TRIGGER', 'master', 'projects', 'projects_ins', 'OVERWRITE' ) = 'CREATE' THEN
CREATE TRIGGER "projects_ins" AFTER INSERT
ORDER 3
ON "master"."projects"
REFERENCING
NEW AS inserted
FOR EACH STATEMENT
BEGIN
/*
* Delete the row from the shadow delete table. (This trigger is only needed if deleted
* primary keys can be re-inserted.)
*/
DELETE FROM "master"."projects_del"
WHERE EXISTS (
SELECT 1
FROM inserted
WHERE "master"."projects_del"."id" = inserted."id"
);
END;
CALL ml_model_register_schema( 'TRIGGER', 'master', 'projects', 'projects_ins', 'DROP TRIGGER "master"."projects"."projects_ins"', '13c6af778141d9b6dfee309a67e64f6c', 0 );
END IF
GO
/* Create the shadow delete trigger 'projects_dlt'. */
CALL ml_model_register_schema_use( 'v2', 'TRIGGER', 'master', 'projects', 'projects_dlt', '709c34a856215a44f5d9b1b0e63abb73' )
GO
IF ml_model_get_schema_action( 'v2', 'TRIGGER', 'master', 'projects', 'projects_dlt', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'TRIGGER', 'master', 'projects', 'projects_dlt' );
DROP TRIGGER "master"."projects"."projects_dlt";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'TRIGGER', 'master', 'projects', 'projects_dlt', 'OVERWRITE' ) = 'CREATE' THEN
CREATE TRIGGER "projects_dlt" AFTER DELETE
ORDER 2
ON "master"."projects"
REFERENCING
OLD AS deleted
FOR EACH STATEMENT
BEGIN
/* Insert the row into the shadow delete table. */
INSERT INTO "master"."projects_del" ( "id", "last_modified" )
SELECT deleted."id",
CURRENT TIMESTAMP
FROM deleted;
END;
CALL ml_model_register_schema( 'TRIGGER', 'master', 'projects', 'projects_dlt', 'DROP TRIGGER "master"."projects"."projects_dlt"', '709c34a856215a44f5d9b1b0e63abb73', 0 );
END IF
GO
/* Create an index for the 'download_cursor' script. */
CALL ml_model_register_schema_use( 'v2', 'INDEX', 'master', 'projects', 'projects_ml', '8f4d69a87e57fc1b18329de943f4dcce' )
GO
IF ml_model_get_schema_action( 'v2', 'INDEX', 'master', 'projects', 'projects_ml', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'INDEX', 'master', 'projects', 'projects_ml' );
DROP INDEX "master"."projects"."projects_ml";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'INDEX', 'master', 'projects', 'projects_ml', 'OVERWRITE' ) = 'CREATE' THEN
CREATE INDEX "projects_ml" ON "master"."projects"
( "last_modified" );
CALL ml_model_register_schema( 'INDEX', 'master', 'projects', 'projects_ml', 'DROP INDEX "master"."projects"."projects_ml"', '8f4d69a87e57fc1b18329de943f4dcce', 0 );
END IF
GO
/* Create an index for the 'download_delete_cursor' script. */
CALL ml_model_register_schema_use( 'v2', 'INDEX', 'master', 'projects_del', 'projects_mld', '8f4d69a87e57fc1b18329de943f4dcce' )
GO
IF ml_model_get_schema_action( 'v2', 'INDEX', 'master', 'projects_del', 'projects_mld', 'OVERWRITE' ) = 'REPLACE' THEN
CALL ml_model_deregister_schema( 'INDEX', 'master', 'projects_del', 'projects_mld' );
DROP INDEX "master"."projects_del"."projects_mld";
END IF
GO
IF ml_model_get_schema_action( 'v2', 'INDEX', 'master', 'projects_del', 'projects_mld', 'OVERWRITE' ) = 'CREATE' THEN
CREATE INDEX "projects_mld" ON "master"."projects_del"
( "last_modified" );
CALL ml_model_register_schema( 'INDEX', 'master', 'projects_del', 'projects_mld', 'DROP INDEX "master"."projects_del"."projects_mld"', '8f4d69a87e57fc1b18329de943f4dcce', 0 );
END IF
GO
CALL ml_model_drop_unused_schema()
GO
COMMIT
GO
CALL ml_add_lang_conn_script_chk (
'v2',
'begin_connection',
'sql',
null,
null
)
GO
CALL ml_add_lang_conn_script_chk (
'v2',
'authenticate_user',
'sql',
null,
null
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_delete',
'sql',
'
/* Delete the row from the consolidated database. */
DELETE FROM "master"."projects"
WHERE "id" = {ml r."id"}
',
'B8B42EF2C6863897031A5C78CB7F9B0B'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'download_cursor',
'sql',
'
SELECT "master"."projects"."id",
"master"."projects"."name"
FROM "master"."projects"
WHERE "master"."projects"."last_modified" >= {ml s.last_table_download}
',
'24042F7EEEADAD71CA81CA74D4DF123B'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'download_delete_cursor',
'sql',
'
SELECT "master"."projects_del"."id"
FROM "master"."projects_del"
WHERE "master"."projects_del"."last_modified" >= {ml s.last_table_download}
',
'DCB33EB96176DB41D341E5D5E8845CBF'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_fetch',
'sql',
null,
null
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'resolve_conflict',
'sql',
'
',
'549D0C590F803284690089186C78C2FE'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_new_row_insert',
'sql',
null,
null
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_old_row_insert',
'sql',
null,
null
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_update',
'sql',
'
/* Update the row in the consolidated database. */
UPDATE "master"."projects"
SET "name" = {ml r."name"}
WHERE "id" = {ml r."id"}
',
'7226968D546026F80B4C092554EBE31D'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_fetch_column_conflict',
'sql',
'
',
'549D0C590F803284690089186C78C2FE'
)
GO
CALL ml_add_lang_table_script_chk (
'v2',
'projects',
'upload_insert',
'sql',
'
/* Insert the row into the consolidated database. */
INSERT INTO "master"."projects" ( "id", "name" )
VALUES ( {ml r."id"}, {ml r."name"} )
',
'9924BECA05848C3FEF861FA2EA022145'
)
GO
CALL ml_add_column (
'v2',
'projects',
null,
null
)
GO
CALL ml_add_column (
'v2',
'projects',
'id',
'integer'
)
GO
CALL ml_add_column (
'v2',
'projects',
'name',
'varchar'
)
GO
CALL ml_add_user( 'remote', 0x81b98b25f7513548a3ce845cfec07c13cbc9c0edef52ac41d4e6bf5c8fa3f275, null )
GO
COMMIT
GO
/*------------------------------------------------------------------------------
* ML Install Script generated 2020-09-09 07:07:59 for SQL Anywhere (Remote) by MobiLink
* 17 Plug-in
*-----------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Drop synchronization profile 'v2_remote'.
*-----------------------------------------------------------------------------*/
DROP SYNCHRONIZATION PROFILE IF EXISTS "v2_remote"
GO
/*------------------------------------------------------------------------------
* Drop the subscription 'v2_remote' and any other subscription for MobiLink user
* 'remote' to publication 'v2'.
*-----------------------------------------------------------------------------*/
IF EXISTS (
SELECT 1
FROM SYS.SYSSYNCSUBSCRIPTIONS
WHERE site_name = 'remote' AND publication_name = 'v2'
) THEN
DROP SYNCHRONIZATION SUBSCRIPTION TO "v2" FOR "remote";
END IF
GO
IF EXISTS (
SELECT 1
FROM SYS.SYSSYNC
WHERE subscription_name = 'v2_remote'
) THEN
DROP SYNCHRONIZATION SUBSCRIPTION "v2_remote";
END IF
GO
/*------------------------------------------------------------------------------
* Drop the user 'remote'.
*-----------------------------------------------------------------------------*/
IF EXISTS (
SELECT 1
FROM SYS.SYSSYNC
WHERE site_name = 'remote'
) THEN
DROP SYNCHRONIZATION USER "remote";
END IF
GO
/*------------------------------------------------------------------------------
* Drop the publication 'v2'.
*-----------------------------------------------------------------------------*/
DROP PUBLICATION IF EXISTS "v2"
GO
COMMIT
GO
IF NOT EXISTS (
SELECT 1
FROM SYS.SYSUSER
WHERE user_name = 'master'
) THEN
GRANT CONNECT TO "master";
END IF
GO
/*------------------------------------------------------------------------------
* Create table 'master.projects'.
*-----------------------------------------------------------------------------*/
DROP TABLE IF EXISTS "master"."projects"
GO
CREATE TABLE "master"."projects" (
"id" integer not null,
"name" varchar(500) null,
PRIMARY KEY ("id")
)
GO
COMMIT
GO
/*------------------------------------------------------------------------------
* Create publication 'v2'.
*-----------------------------------------------------------------------------*/
CREATE PUBLICATION IF NOT EXISTS "v2" (
TABLE "master"."projects"
)
GO
/*------------------------------------------------------------------------------
* Create the user 'remote'.
*-----------------------------------------------------------------------------*/
CREATE SYNCHRONIZATION USER "remote"
GO
/*------------------------------------------------------------------------------
* Create subscription 'v2_remote' to 'v2' for 'remote'.
*-----------------------------------------------------------------------------*/
CREATE SYNCHRONIZATION SUBSCRIPTION "v2_remote" TO "v2" FOR "remote"
TYPE tcpip ADDRESS 'host=REDACTED;port=2439'
SCRIPT VERSION 'v2'
GO
/*------------------------------------------------------------------------------
* Create synchronization profile 'v2_remote'.
*-----------------------------------------------------------------------------*/
CREATE OR REPLACE SYNCHRONIZATION PROFILE "v2_remote" 'Subscription=v2_remote;MobiLinkPwd=remote'
GO
COMMIT
GO
COMMIT
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment