Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location fix #65

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
34 changes: 34 additions & 0 deletions database/migrations/20240522080439_recentLocationsView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
const { commonFields } = require('./20230405144107_setup');
exports.up = function (knex) {
return knex.schema.dropTable('recentLocations').raw(`
CREATE VIEW recent_locations AS
SELECT DISTINCT ON (location->>'cadastral_id', "created_by", "tenant_id")
location->>'name' AS name,
location->>'cadastral_id' AS cadastral_id,
location->>'municipality' AS municipality,
"tenant_id",
"created_by" AS user_id,
"id" AS "geom",
"event_time"
FROM fish_stockings
ORDER BY location->>'cadastral_id', "user_id", "tenant_id", "event_time" DESC;
`);
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropView('recentLocations').createTable('recentLocations', (table) => {
table.increments('id');
table.integer('tenant');
table.integer('user');
table.jsonb('recent');
commonFields(table);
});
};
Loading
Loading