Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1164 from sarracini/gh1156
Browse files Browse the repository at this point in the history
feat(metadata): Closes #1156 Add metadata_source field to MetadataStore
  • Loading branch information
sarracini committed Aug 25, 2016
2 parents d0f1021 + 31e9614 commit 5c21f03
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
7 changes: 4 additions & 3 deletions addon/MetadataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const SQL_DDLS = [
const SQL_LAST_INSERT_ROWID = "SELECT last_insert_rowid() AS lastInsertRowID";

const SQL_INSERT_METADATA = `INSERT INTO page_metadata
(cache_key, places_url, title, type, description, media_url, expired_at)
(cache_key, places_url, title, type, description, media_url, expired_at, metadata_source)
VALUES
(:cache_key, :places_url, :title, :type, :description, :media_url, :expired_at)`;
(:cache_key, :places_url, :title, :type, :description, :media_url, :expired_at, :metadata_source)`;

const SQL_INSERT_IMAGES = `INSERT INTO page_images
(url, type, height, width, color)
Expand Down Expand Up @@ -186,7 +186,8 @@ MetadataStore.prototype = {
type: aRow.type,
description: aRow.description,
media_url: aRow.media && aRow.media.url,
expired_at: aRow.expired_at
expired_at: aRow.expired_at,
metadata_source: aRow.metadata_source
};
},

Expand Down
5 changes: 5 additions & 0 deletions addon/MetadataStoreMigration.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ exports.MIGRATIONS = [
version: "1.0.0",
description: "A dummy migration as a sentinel",
statements: []
},
{
version: "1.0.1",
description: "Add a metadata_source field to MetadataStore",
statements: ["ALTER TABLE page_metadata ADD COLUMN metadata_source VARCHAR(32) DEFAULT 'Embedly'"]
}
];
1 change: 1 addition & 0 deletions metadata_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description | String | The meta description of the page
media_url | String | The URL for an embedded media item (audio/video)
created_at | datetime | The date and time that this metadata row was inserted/created
expired_at | Long | The date and time this metadata row will expire
metadata_source | String | The source in which the metadata was computed

# Images Table
A row in this table represents a single image which appears on a page visited by a user, including favicons and rich icons. Each row in the metadata table will have multiple corresponding images in this table. A single row in this table may belong to multiple metadata page rows, ie a favicon which is identical for multiple pages.
Expand Down
3 changes: 3 additions & 0 deletions test/lib/MetastoreFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const gMetadataFixture = [
title: "We're building a better Internet",
media: {type: "video", url: "https://www.mozilla.org/media/video/mozilla.mp4"},
expired_at: 1475280000000, // "2016-10-01 00:00:00",
metadata_source: "Embedly",
type: "html",
favicon_colors,
images
Expand All @@ -149,6 +150,7 @@ const gMetadataFixture = [
title: "Browse Freely",
media: {type: "video", url: "https://www.mozilla.org/media/video/firefox.mp4"},
expired_at: 1475280000000, // "2016-10-01 00:00:00",
metadata_source: "Embedly",
type: "html",
favicon_colors: favicon_colors_firefox,
images: images_firefox
Expand All @@ -161,6 +163,7 @@ const gMetadataFixture = [
title: "Browse Freely",
media: {type: "video", url: "https://www.mozilla.org/media/video/firefox.mp4"},
expired_at: 1475280000000, // "2016-10-01 00:00:00",
metadata_source: "Embedly",
type: "html",
favicon_colors: favicon_colors_firefox,
images: images_firefox
Expand Down
4 changes: 1 addition & 3 deletions test/test-MetadataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ before(exports, function*() {
});

after(exports, function*() {
yield gMetadataStore.asyncReset();
yield waitForAsyncReset();
yield gMetadataStore.asyncClose();
yield gMetadataStore.asyncTearDown();
});

require("sdk/test").run(exports);
14 changes: 14 additions & 0 deletions test/test-MetadataStoreMigration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,18 @@ exports.test_migration = function*(assert) {
yield metaStore.asyncTearDown();
};

exports.test_migration_1_0_1 = function*(assert) {
let metaStore = new MetadataStore();
yield metaStore.asyncConnect();

// Check the version gets tracked correctly
let result = yield metaStore.asyncExecuteQuery("SELECT version FROM migrations", {columns: ["version"]});
assert.equal(result[0].version, "1.0.1", "It should return the current version");

// Check the new column
let columns = yield metaStore.asyncExecuteQuery("PRAGMA table_info(page_metadata)");
let newColumn = columns[columns.length - 1]; // The last column should be the one in the migration
assert.equal(newColumn[1], "metadata_source", "It should add metadata_source column");
yield metaStore.asyncTearDown();
};
require("sdk/test").run(exports);

0 comments on commit 5c21f03

Please sign in to comment.