Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

31.5.0 backport #4564

Merged
merged 3 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 31.5.0

Note: this is a server release. There are no user facing features or bug fixes in this release. The changes are for reducing the risk of running a manual database migration. (See comments in https://github.com/mozilla-services/screenshots/pull/4417 for details on the migration.)

* Skip DB downgrades. ([#4484](https://github.com/mozilla-services/screenshots/issues/4484)) ([#4490](https://github.com/mozilla-services/screenshots/issues/4490)) [47cf0ed](https://github.com/mozilla-services/screenshots/commit/47cf0ed)

## Version 31.3.0

Note: this is a server release (31.{0,1,2}.0 did not go into
Expand Down
3 changes: 2 additions & 1 deletion bin/build-docker-image
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -eu

export NODE_ENV=production
export NODE_ENV=${NODE_ENV:-production}

cd "$(dirname ${BASH_SOURCE[0]})/.."

if [[ $# = 0 ]] ; then
Expand Down
2 changes: 2 additions & 0 deletions bin/release-version
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ case "$channel" in
mkdir -p build
touch build/.backend.txt
SCREENSHOTS_BACKEND=https://screenshots.dev.mozaws.net SCREENSHOTS_SENTRY="$dev_sentry" make unsigned_bootstrap_xpi
export NODE_ENV=dev
./bin/build-docker-image mozilla latest
echo
echo "Dev deployment automatically triggered, see #screenshots IRC for status"
Expand All @@ -58,6 +59,7 @@ case "$channel" in
# Forces update of the add-on version:
touch build/.backend.txt
SCREENSHOTS_BACKEND=https://screenshots.stage.mozaws.net SCREENSHOTS_SENTRY="$stage_sentry" make unsigned_bootstrap_xpi
export NODE_ENV=production
./bin/build-docker-image mozilla
echo
echo "Stage deployment automatically triggered, see #screenshots IRC for status"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firefox-screenshots",
"description": "An experiment in creating better shareable versions of content.",
"version": "31.4.0",
"version": "31.5.0",
"author": "Mozilla (https://mozilla.org/)",
"bugs": {
"url": "https://github.com/mozilla-services/screenshots/issues"
Expand Down
7 changes: 7 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ const conf = convict({
env: "RDS_NAME",
arg: "db-name"
},
disableDownPatches: {
doc: "Skip database downgrade patches",
format: Boolean,
default: false,
env: "NO_PG_DOWNGRADES",
arg: "no-pg-downgrades"
},
forceDbVersion: {
doc: "Force database version (for use in downgrades)",
format: "int",
Expand Down
54 changes: 35 additions & 19 deletions server/src/dbschema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const config = require("./config").getProperties();
const db = require("./db");
const Keygrip = require("keygrip");
const pgpatcher = require("pg-patcher");
Expand Down Expand Up @@ -35,21 +36,30 @@ exports.forceDbVersion = function(version) {
exports.createTables = function() {
mozlog.info("setting-up-tables-on", {db: db.constr});
return db.getConnection().then(([conn, done]) => {
const dirname = path.join(__dirname, "db-patches");
mozlog.info("loading-patches-from", {dirname});
return new Promise((resolve, reject) => {
pgpatcher(conn, MAX_DB_LEVEL, {dir: dirname}, function(err) {
if (err) {
mozlog.error("error-patching", {
msg: `Error patching database to level ${MAX_DB_LEVEL}!`,
err
});
done();
reject(err);
} else {
mozlog.info("db-level", {msg: `Database is now at level ${MAX_DB_LEVEL}`});
resolve();
}
return getCurrentDbPatchLevel().then(currentDbPatchLevel => {
if (currentDbPatchLevel >= MAX_DB_LEVEL
&& (process.env.NODE_ENV === "production" || config.db.disableDownPatches)) {
mozlog.info("skip-db-down-patches",
{ msg: `Database patch level of ${currentDbPatchLevel} is greater than or equal to the hard coded level of ${MAX_DB_LEVEL}.` });
return Promise.resolve();
}

const dirname = path.join(__dirname, "db-patches");
mozlog.info("loading-patches-from", {dirname});
return new Promise((resolve, reject) => {
pgpatcher(conn, MAX_DB_LEVEL, {dir: dirname}, function(err) {
if (err) {
mozlog.error("error-patching", {
msg: `Error patching database to level ${MAX_DB_LEVEL}!`,
err
});
done();
reject(err);
} else {
mozlog.info("db-level", {msg: `Database is now at level ${MAX_DB_LEVEL}`});
resolve();
}
});
});
});
}).then(() => {
Expand Down Expand Up @@ -136,8 +146,6 @@ exports.createKeygrip = function() {
});
};



/** Returns a promise that generates a new largish ASCII random key */
function makeKey() {
return new Promise(function(resolve, reject) {
Expand All @@ -151,11 +159,19 @@ function makeKey() {
});
}

function getCurrentDbPatchLevel() {
return db.select(`SELECT value FROM property WHERE key = 'patch'`).then(rows => {
return parseInt(rows[0].value, 10);
}).catch(e => {
return 0;
});
}

exports.connectionOK = function() {
if (!keys) {
return Promise.resolve(false);
}
return db.select(`SELECT value FROM property WHERE key = 'patch'`).then((rows) => {
return parseInt(rows[0].value, 10) === MAX_DB_LEVEL;
return getCurrentDbPatchLevel().then(currentLevel => {
return currentLevel >= MAX_DB_LEVEL;
});
};
2 changes: 2 additions & 0 deletions test/server/test_file_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def restart_server(**extra_env):
if 'updated-metrics' in line:
# Last log message before the server is running
break
if 'skip-db-down-patches' in line:
break
print(" Server started")


Expand Down