Skip to content

Commit c954456

Browse files
shestakovenmo4islonaCopilot
authored
feat: add new version of PG, restrict PG version change (#113)
* feat: add new version of PG, restrict PG version change * Update src/commands/deploy.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Eugene Formanenko <mo4islona@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0046125 commit c954456

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@subsquid/cli",
33
"description": "squid cli tool",
4-
"version": "3.3.3",
4+
"version": "3.3.4",
55
"license": "GPL-3.0-or-later",
66
"repository": {
77
"type": "git",
@@ -81,7 +81,7 @@
8181
"@oclif/plugin-autocomplete": "3.2.2",
8282
"@oclif/plugin-warn-if-update-available": "^3.1.13",
8383
"@subsquid/commands": "^2.3.1",
84-
"@subsquid/manifest": "^2.1.2",
84+
"@subsquid/manifest": "^2.1.3",
8585
"@types/fast-levenshtein": "^0.0.4",
8686
"@types/lodash": "^4.17.7",
8787
"@types/targz": "^1.0.4",

src/commands/deploy.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { promisify } from 'util';
44

55
import { Args, Flags, ux as CliUx } from '@oclif/core';
6-
import { Manifest } from '@subsquid/manifest';
6+
import { Manifest, ManifestValue } from '@subsquid/manifest';
77
import chalk from 'chalk';
88
import diff from 'cli-diff';
99
import { globSync } from 'glob';
@@ -258,6 +258,17 @@ export default class Deploy extends DeployCommand {
258258
if (!update) return;
259259
}
260260

261+
/**
262+
* Prevent deploying if the Postgres version has changed (requires hard reset)
263+
*/
264+
const versionMismatch = getPostgresVersionMismatch(target, manifest);
265+
if (!hardReset && versionMismatch) {
266+
this.error(
267+
`The squid ${printSquid(target!)} is currently using Postgres ${versionMismatch.currentVersion}, but the new manifest specifies Postgres ${versionMismatch.newVersion}. ` +
268+
`Changing the Postgres version requires a hard reset. Please do it explicitly using "--hard-reset" flag.`,
269+
);
270+
}
271+
261272
/**
262273
* Warn if the existing squid has a Postgres addon but the new manifest removes it
263274
*/
@@ -545,3 +556,20 @@ export function getIgnorePatterns(ignoreDir: string, raw: string) {
545556
function toRootPattern(pattern: string) {
546557
return pattern.startsWith('/') ? pattern : `/${pattern}`;
547558
}
559+
560+
export function getPostgresVersionMismatch(
561+
target: Squid | null,
562+
manifest: Manifest,
563+
): { currentVersion: string; newVersion: string } | null {
564+
if (!target?.addons?.postgres || !manifest.deploy?.addons?.postgres) return null;
565+
566+
const currentManifest = target.manifest.current as ManifestValue;
567+
const currentVersion = currentManifest.deploy?.addons?.postgres?.version;
568+
const newVersion = manifest.deploy.addons.postgres.version;
569+
570+
if (currentVersion && newVersion && currentVersion !== newVersion) {
571+
return { currentVersion, newVersion };
572+
}
573+
574+
return null;
575+
}

src/commands/deploy.unit.spec.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getIgnorePatterns } from './deploy';
1+
import { getIgnorePatterns, getPostgresVersionMismatch } from './deploy';
22

33
describe('Deploy', () => {
44
describe('get squid ignore paths', () => {
@@ -25,4 +25,58 @@ describe('Deploy', () => {
2525
expect(patterns).toEqual(['/dir/.git', '/dir/builds', '/dir/abi', '/dir/**/test', '/dir/**/.env', '/dir/**/foo']);
2626
});
2727
});
28+
29+
describe('getPostgresVersionMismatch', () => {
30+
function makeTarget(pgVersion?: string) {
31+
return {
32+
addons: pgVersion
33+
? { postgres: { connections: [], disk: { usageStatus: 'NORMAL', usedBytes: 0, totalBytes: 0 } } }
34+
: undefined,
35+
manifest: {
36+
current: pgVersion
37+
? { deploy: { addons: { postgres: { version: pgVersion } } } }
38+
: { deploy: {} },
39+
raw: '',
40+
},
41+
} as any;
42+
}
43+
44+
function makeManifest(pgVersion?: string) {
45+
return {
46+
deploy: pgVersion ? { addons: { postgres: { version: pgVersion } } } : { addons: {} },
47+
} as any;
48+
}
49+
50+
it('returns mismatch when versions differ', () => {
51+
const result = getPostgresVersionMismatch(makeTarget('16'), makeManifest('17'));
52+
expect(result).toEqual({ currentVersion: '16', newVersion: '17' });
53+
});
54+
55+
it('returns null when versions match', () => {
56+
const result = getPostgresVersionMismatch(makeTarget('16'), makeManifest('16'));
57+
expect(result).toBeNull();
58+
});
59+
60+
it('returns null when target is null', () => {
61+
const result = getPostgresVersionMismatch(null, makeManifest('17'));
62+
expect(result).toBeNull();
63+
});
64+
65+
it('returns null when target has no postgres addon', () => {
66+
const result = getPostgresVersionMismatch(makeTarget(), makeManifest('17'));
67+
expect(result).toBeNull();
68+
});
69+
70+
it('returns null when new manifest has no postgres addon', () => {
71+
const result = getPostgresVersionMismatch(makeTarget('16'), makeManifest());
72+
expect(result).toBeNull();
73+
});
74+
75+
it('returns null when current manifest has no postgres version', () => {
76+
const target = makeTarget('16');
77+
target.manifest.current = { deploy: { addons: { postgres: {} } } };
78+
const result = getPostgresVersionMismatch(target, makeManifest('17'));
79+
expect(result).toBeNull();
80+
});
81+
});
2882
});

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ __metadata:
14111411
"@oclif/plugin-autocomplete": "npm:3.2.2"
14121412
"@oclif/plugin-warn-if-update-available": "npm:^3.1.13"
14131413
"@subsquid/commands": "npm:^2.3.1"
1414-
"@subsquid/manifest": "npm:^2.1.1"
1414+
"@subsquid/manifest": "npm:^2.1.3"
14151415
"@types/async-retry": "npm:^1.4.8"
14161416
"@types/blessed": "npm:^0.1.25"
14171417
"@types/cross-spawn": "npm:^6.0.6"
@@ -1505,14 +1505,14 @@ __metadata:
15051505
languageName: node
15061506
linkType: hard
15071507

1508-
"@subsquid/manifest@npm:^2.1.1":
1509-
version: 2.1.1
1510-
resolution: "@subsquid/manifest@npm:2.1.1"
1508+
"@subsquid/manifest@npm:^2.1.3":
1509+
version: 2.1.3
1510+
resolution: "@subsquid/manifest@npm:2.1.3"
15111511
dependencies:
15121512
joi: "npm:17.13.3"
15131513
js-yaml: "npm:^4.1.0"
15141514
lodash: "npm:^4.17.21"
1515-
checksum: 10c0/553090993987a2472855b291542e0ad0c91db794c6bbedbd88f9e924cf56ac421ec7222370207627837d71c8d142d347c0604bdc51e143c540df170dbd3b32af
1515+
checksum: 10c0/ad569035cebd8c4fc6c67f7af7e827cc5a5925186fcb9205c88f28f18257779cb8f456cfbe0ae5ce1d735928cdc530b1b0974ca088a13056b4f4e6bab24f1025
15161516
languageName: node
15171517
linkType: hard
15181518

0 commit comments

Comments
 (0)