diff --git a/migrations/20250622173922-add-composite-index-to-captures.js b/migrations/20250622173922-add-composite-index-to-captures.js new file mode 100644 index 00000000..2741e407 --- /dev/null +++ b/migrations/20250622173922-add-composite-index-to-captures.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20250622173922-add-composite-index-to-captures-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20250622173922-add-composite-index-to-captures-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/migrations/sqls/20250622173922-add-composite-index-to-captures-down.sql b/migrations/sqls/20250622173922-add-composite-index-to-captures-down.sql new file mode 100644 index 00000000..0be36b6d --- /dev/null +++ b/migrations/sqls/20250622173922-add-composite-index-to-captures-down.sql @@ -0,0 +1,2 @@ +/* Replace with your SQL commands */ +DROP INDEX capture_tree_id_captured_at_idx; \ No newline at end of file diff --git a/migrations/sqls/20250622173922-add-composite-index-to-captures-up.sql b/migrations/sqls/20250622173922-add-composite-index-to-captures-up.sql new file mode 100644 index 00000000..eb22715d --- /dev/null +++ b/migrations/sqls/20250622173922-add-composite-index-to-captures-up.sql @@ -0,0 +1,2 @@ +/* Replace with your SQL commands */ +CREATE INDEX capture_tree_id_captured_at_idx ON capture (tree_id, captured_at); \ No newline at end of file