Skip to content

Commit 5951d27

Browse files
committed
prototyping idea for mass-migration
1 parent a662baa commit 5951d27

File tree

6 files changed

+91
-21
lines changed

6 files changed

+91
-21
lines changed

docs/cli.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,19 +798,21 @@ <h2 id="migrate">migrate</h2>
798798
</li>
799799
<li><p>The integration auth used is not shared.</p>
800800
</li>
801-
</ul><p>Alternatively, you can pass the <code>--account</code> flag, (i.e. <code>zapier migrate 1.0.0 1.0.1 --account=account@example.com</code>). This will migrate all users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member.</p><p><strong>The <code>--account</code> flag should be used cautiously as it can break shared Zaps for other users in Team or Company accounts.</strong></p><p>You cannot pass both <code>PERCENT</code> and <code>--user</code> or <code>--account</code>.</p><p>You cannot pass both <code>--user</code> and <code>--account</code>.</p><p><strong>Arguments</strong></p><ul>
801+
</ul><p>Alternatively, you can pass the <code>--account</code> flag, (i.e. <code>zapier migrate 1.0.0 1.0.1 --account=account@example.com</code>). This will migrate all users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member.</p><p><strong>The <code>--account</code> flag should be used cautiously as it can break shared Zaps for other users in Team or Company accounts.</strong></p><p>You cannot pass both <code>PERCENT</code> and <code>--user</code> or <code>--account</code>.</p><p>You cannot pass both <code>--user</code> and <code>--account</code>.</p><p>When you , you can also pass the <code>--include-all-compatible-versions</code> flag to migrate all older compatible versions of the integration. For example, if you have versions 1.0.0, 1.1.0 and 1.2.0 which you would like to migrate to version 2.0.0, you can run the migrate command with <code>fromVersion</code> set to 1.2.0 and use the <code>--include-all-compatible-versions</code> flag.</p><p><strong>The <code>--include-all-compatible-versions</code> flag should be used cautiously as it is a bulk operation that will possibly affect more than just one version. It also only supports forward migrations; rolling back to a previous version would require individual migrations.</strong></p><p><strong>Arguments</strong></p><ul>
802802
<li>(required) <code>fromVersion</code> | The version FROM which to migrate users.</li>
803803
<li>(required) <code>toVersion</code> | The version TO which to migrate users.</li>
804804
<li><code>percent</code> | Percentage (between 1 and 100) of users to migrate.</li>
805805
</ul><p><strong>Flags</strong></p><ul>
806806
<li><code>--user</code> | Migrates all of a users&apos; Private Zaps within all accounts for which the specified user is a member</li>
807807
<li><code>--account</code> | Migrates all of a users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member</li>
808+
<li><code>--includeAllCompatibleVersions</code> | Schedules the migration of other compatible versions besides the &apos;fromVersion&apos;, if any are available. Compatible versions are those that are older than the &apos;fromVersion&apos; but still share the same major version number as the &apos;fromVersion&apos;.</li>
808809
<li><code>-d, --debug</code> | Show extra debugging output.</li>
809810
</ul><p><strong>Examples</strong></p><ul>
810811
<li><code>zapier migrate 1.0.0 1.0.1</code></li>
811812
<li><code>zapier migrate 1.0.1 2.0.0 10</code></li>
812813
<li><code>zapier migrate 2.0.0 2.0.1 --user=user@example.com</code></li>
813814
<li><code>zapier migrate 2.0.0 2.0.1 --account=account@example.com</code></li>
815+
<li><code>zapier migrate 2.4.0 2.5.0 --include-all-compatible-versions</code></li>
814816
</ul>
815817
</div>
816818
<div class="col-md-7 col-sm-12 col-height is-empty docs-code">

docs/cli.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ You cannot pass both `PERCENT` and `--user` or `--account`.
368368

369369
You cannot pass both `--user` and `--account`.
370370

371+
When you , you can also pass the `--include-all-compatible-versions` flag to migrate all older compatible versions of the integration. For example, if you have versions 1.0.0, 1.1.0 and 1.2.0 which you would like to migrate to version 2.0.0, you can run the migrate command with `fromVersion` set to 1.2.0 and use the `--include-all-compatible-versions` flag.
372+
373+
**The `--include-all-compatible-versions` flag should be used cautiously as it is a bulk operation that will possibly affect more than just one version. It also only supports forward migrations; rolling back to a previous version would require individual migrations.**
374+
371375
**Arguments**
372376
* (required) `fromVersion` | The version FROM which to migrate users.
373377
* (required) `toVersion` | The version TO which to migrate users.
@@ -376,13 +380,15 @@ You cannot pass both `--user` and `--account`.
376380
**Flags**
377381
* `--user` | Migrates all of a users' Private Zaps within all accounts for which the specified user is a member
378382
* `--account` | Migrates all of a users' Zaps, Private & Shared, within all accounts for which the specified user is a member
383+
* `--includeAllCompatibleVersions` | Schedules the migration of other compatible versions besides the 'fromVersion', if any are available. Compatible versions are those that are older than the 'fromVersion' but still share the same major version number as the 'fromVersion'.
379384
* `-d, --debug` | Show extra debugging output.
380385

381386
**Examples**
382387
* `zapier migrate 1.0.0 1.0.1`
383388
* `zapier migrate 1.0.1 2.0.0 10`
384389
* `zapier migrate 2.0.0 2.0.1 --user=user@example.com`
385390
* `zapier migrate 2.0.0 2.0.1 --account=account@example.com`
391+
* `zapier migrate 2.4.0 2.5.0 --include-all-compatible-versions`
386392

387393

388394
## promote

packages/cli/docs/cli.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,19 +798,21 @@ <h2 id="migrate">migrate</h2>
798798
</li>
799799
<li><p>The integration auth used is not shared.</p>
800800
</li>
801-
</ul><p>Alternatively, you can pass the <code>--account</code> flag, (i.e. <code>zapier migrate 1.0.0 1.0.1 --account=account@example.com</code>). This will migrate all users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member.</p><p><strong>The <code>--account</code> flag should be used cautiously as it can break shared Zaps for other users in Team or Company accounts.</strong></p><p>You cannot pass both <code>PERCENT</code> and <code>--user</code> or <code>--account</code>.</p><p>You cannot pass both <code>--user</code> and <code>--account</code>.</p><p><strong>Arguments</strong></p><ul>
801+
</ul><p>Alternatively, you can pass the <code>--account</code> flag, (i.e. <code>zapier migrate 1.0.0 1.0.1 --account=account@example.com</code>). This will migrate all users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member.</p><p><strong>The <code>--account</code> flag should be used cautiously as it can break shared Zaps for other users in Team or Company accounts.</strong></p><p>You cannot pass both <code>PERCENT</code> and <code>--user</code> or <code>--account</code>.</p><p>You cannot pass both <code>--user</code> and <code>--account</code>.</p><p>When you , you can also pass the <code>--include-all-compatible-versions</code> flag to migrate all older compatible versions of the integration. For example, if you have versions 1.0.0, 1.1.0 and 1.2.0 which you would like to migrate to version 2.0.0, you can run the migrate command with <code>fromVersion</code> set to 1.2.0 and use the <code>--include-all-compatible-versions</code> flag.</p><p><strong>The <code>--include-all-compatible-versions</code> flag should be used cautiously as it is a bulk operation that will possibly affect more than just one version. It also only supports forward migrations; rolling back to a previous version would require individual migrations.</strong></p><p><strong>Arguments</strong></p><ul>
802802
<li>(required) <code>fromVersion</code> | The version FROM which to migrate users.</li>
803803
<li>(required) <code>toVersion</code> | The version TO which to migrate users.</li>
804804
<li><code>percent</code> | Percentage (between 1 and 100) of users to migrate.</li>
805805
</ul><p><strong>Flags</strong></p><ul>
806806
<li><code>--user</code> | Migrates all of a users&apos; Private Zaps within all accounts for which the specified user is a member</li>
807807
<li><code>--account</code> | Migrates all of a users&apos; Zaps, Private &amp; Shared, within all accounts for which the specified user is a member</li>
808+
<li><code>--includeAllCompatibleVersions</code> | Schedules the migration of other compatible versions besides the &apos;fromVersion&apos;, if any are available. Compatible versions are those that are older than the &apos;fromVersion&apos; but still share the same major version number as the &apos;fromVersion&apos;.</li>
808809
<li><code>-d, --debug</code> | Show extra debugging output.</li>
809810
</ul><p><strong>Examples</strong></p><ul>
810811
<li><code>zapier migrate 1.0.0 1.0.1</code></li>
811812
<li><code>zapier migrate 1.0.1 2.0.0 10</code></li>
812813
<li><code>zapier migrate 2.0.0 2.0.1 --user=user@example.com</code></li>
813814
<li><code>zapier migrate 2.0.0 2.0.1 --account=account@example.com</code></li>
815+
<li><code>zapier migrate 2.4.0 2.5.0 --include-all-compatible-versions</code></li>
814816
</ul>
815817
</div>
816818
<div class="col-md-7 col-sm-12 col-height is-empty docs-code">

packages/cli/docs/cli.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ You cannot pass both `PERCENT` and `--user` or `--account`.
368368

369369
You cannot pass both `--user` and `--account`.
370370

371+
When you , you can also pass the `--include-all-compatible-versions` flag to migrate all older compatible versions of the integration. For example, if you have versions 1.0.0, 1.1.0 and 1.2.0 which you would like to migrate to version 2.0.0, you can run the migrate command with `fromVersion` set to 1.2.0 and use the `--include-all-compatible-versions` flag.
372+
373+
**The `--include-all-compatible-versions` flag should be used cautiously as it is a bulk operation that will possibly affect more than just one version. It also only supports forward migrations; rolling back to a previous version would require individual migrations.**
374+
371375
**Arguments**
372376
* (required) `fromVersion` | The version FROM which to migrate users.
373377
* (required) `toVersion` | The version TO which to migrate users.
@@ -376,13 +380,15 @@ You cannot pass both `--user` and `--account`.
376380
**Flags**
377381
* `--user` | Migrates all of a users' Private Zaps within all accounts for which the specified user is a member
378382
* `--account` | Migrates all of a users' Zaps, Private & Shared, within all accounts for which the specified user is a member
383+
* `--includeAllCompatibleVersions` | Schedules the migration of other compatible versions besides the 'fromVersion', if any are available. Compatible versions are those that are older than the 'fromVersion' but still share the same major version number as the 'fromVersion'.
379384
* `-d, --debug` | Show extra debugging output.
380385

381386
**Examples**
382387
* `zapier migrate 1.0.0 1.0.1`
383388
* `zapier migrate 1.0.1 2.0.0 10`
384389
* `zapier migrate 2.0.0 2.0.1 --user=user@example.com`
385390
* `zapier migrate 2.0.0 2.0.1 --account=account@example.com`
391+
* `zapier migrate 2.4.0 2.5.0 --include-all-compatible-versions`
386392

387393

388394
## promote

packages/cli/src/oclif/commands/migrate.js

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { flags } = require('@oclif/command');
22

33
const BaseCommand = require('../ZapierBaseCommand');
44
const PromoteCommand = require('./promote');
5-
const { callAPI } = require('../../utils/api');
5+
const { callAPI, listVersions } = require('../../utils/api');
6+
const { isVersionCompatible } = require('../../utils/semver-compatibility');
67
const { buildFlags } = require('../buildFlags');
78

89
class MigrateCommand extends BaseCommand {
@@ -16,6 +17,9 @@ class MigrateCommand extends BaseCommand {
1617
const user = this.flags.user;
1718
const fromVersion = this.args.fromVersion;
1819
const toVersion = this.args.toVersion;
20+
const includeAllCompatibleVersions =
21+
this.flags.includeAllCompatibleVersions;
22+
1923
let flagType;
2024

2125
if (user || account) {
@@ -36,6 +40,23 @@ class MigrateCommand extends BaseCommand {
3640

3741
const app = await this.getWritableApp();
3842

43+
// `versionsToMigrate` should at least include the user-specified `fromVersion`
44+
const versionsToMigrate = [fromVersion];
45+
46+
// If the `--include-all-compatible-versions` flag is active,we fetch all available
47+
// versions, filter for which are compatible and then add them to `versionsToMigrate`
48+
if (includeAllCompatibleVersions) {
49+
const { versions } = await listVersions();
50+
const versionStrings = versions.map((v) => v.version);
51+
const compatibleVersions = versionStrings.filter((v) =>
52+
isVersionCompatible({ versionCurrent: v, versionGoal: toVersion })
53+
);
54+
55+
if (compatibleVersions.length > 0) {
56+
versionsToMigrate.push(...compatibleVersions);
57+
}
58+
}
59+
3960
let promoteFirst = false;
4061
if (
4162
percent === 100 &&
@@ -61,37 +82,44 @@ class MigrateCommand extends BaseCommand {
6182
const body = {
6283
job: {
6384
name: 'migrate',
64-
from_version: fromVersion,
6585
to_version: toVersion,
6686
email: user || account,
6787
email_type: flagType,
6888
},
6989
};
70-
if (user || account) {
71-
this.startSpinner(
72-
`Starting migration from ${fromVersion} to ${toVersion} for ${
73-
user || account
74-
}`
75-
);
76-
} else {
77-
this.startSpinner(
78-
`Starting migration from ${fromVersion} to ${toVersion} for ${percent}%`
79-
);
80-
}
90+
8191
if (percent) {
8292
body.job.percent_human = percent;
8393
}
8494

8595
const url = `/apps/${app.id}/migrations`;
8696

87-
try {
88-
await callAPI(url, { method: 'POST', body });
89-
} finally {
90-
this.stopSpinner();
97+
for (const version of versionsToMigrate) {
98+
body.job.from_version = version;
99+
100+
if (user || account) {
101+
this.startSpinner(
102+
`Starting migration from ${fromVersion} to ${toVersion} for ${
103+
user || account
104+
}`
105+
);
106+
} else {
107+
this.startSpinner(
108+
`Starting migration from ${fromVersion} to ${toVersion} for ${percent}%`
109+
);
110+
}
111+
112+
try {
113+
await callAPI(url, { method: 'POST', body });
114+
} catch (err) {
115+
this.error(err);
116+
} finally {
117+
this.stopSpinner();
118+
}
91119
}
92120

93121
this.log(
94-
'\nMigration successfully queued, please check `zapier jobs` to track the status. Migrations usually take between 5-10 minutes.'
122+
'\nMigration(s) successfully queued, please check `zapier jobs` to track their status. Migrations usually take between 5-10 minutes.'
95123
);
96124
}
97125
}
@@ -106,6 +134,10 @@ MigrateCommand.flags = buildFlags({
106134
description:
107135
"Migrates all of a users' Zaps, Private & Shared, within all accounts for which the specified user is a member",
108136
}),
137+
includeAllCompatibleVersions: flags.string({
138+
description:
139+
"Schedules the migration of other compatible versions besides the 'fromVersion', if any are available. Compatible versions are those that are older than the 'fromVersion' but still share the same major version number as the 'fromVersion'.",
140+
}),
109141
},
110142
});
111143

@@ -134,6 +166,7 @@ MigrateCommand.examples = [
134166
'zapier migrate 1.0.1 2.0.0 10',
135167
'zapier migrate 2.0.0 2.0.1 --user=user@example.com',
136168
'zapier migrate 2.0.0 2.0.1 --account=account@example.com',
169+
'zapier migrate 2.4.0 2.5.0 --include-all-compatible-versions',
137170
];
138171
MigrateCommand.description = `Migrate a percentage of users or a single user from one version of your integration to another.
139172
@@ -159,6 +192,11 @@ Alternatively, you can pass the \`--account\` flag, (i.e. \`zapier migrate 1.0.0
159192
160193
You cannot pass both \`PERCENT\` and \`--user\` or \`--account\`.
161194
162-
You cannot pass both \`--user\` and \`--account\`.`;
195+
You cannot pass both \`--user\` and \`--account\`.
196+
197+
When you , you can also pass the \`--include-all-compatible-versions\` flag to migrate all older compatible versions of the integration. For example, if you have versions 1.0.0, 1.1.0 and 1.2.0 which you would like to migrate to version 2.0.0, you can run the migrate command with \`fromVersion\` set to 1.2.0 and use the \`--include-all-compatible-versions\` flag.
198+
199+
**The \`--include-all-compatible-versions\` flag should be used cautiously as it is a bulk operation that will possibly affect more than just one version. It also only supports forward migrations; rolling back to a previous version would require individual migrations.**
200+
`;
163201

164202
module.exports = MigrateCommand;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const semver = require('semver');
2+
3+
function isVersionCompatible({ versionCurrent, versionGoal }) {
4+
// First, check if both versions have the same major version
5+
if (semver.major(versionGoal) !== semver.major(versionCurrent)) {
6+
return false;
7+
}
8+
9+
// Create a range that represents all versions less than or equal to 'versionGoal'
10+
const versionRange = `<=${versionGoal}`;
11+
12+
// Check if 'versionCurrent' falls within this range
13+
return semver.satisfies(versionCurrent, versionRange);
14+
}
15+
16+
module.exports = { isVersionCompatible };

0 commit comments

Comments
 (0)