Skip to content
Snippets Groups Projects
Verified Commit 166ad559 authored by Louis's avatar Louis :fire:
Browse files

Create classification_roots table

parent 00e6c0b3
No related branches found
No related tags found
No related merge requests found
module.exports = {
up: (migration, Types) => {
return migration.createTable('classification_roots', {
metric_id: {
type: Types.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
upload_id: {
type: Types.UUID,
allowNull: false,
references: {
model: 'uploads',
key: 'id',
},
},
image_id: {
type: Types.UUID,
allowNull: false,
},
url: {
type: Types.TEXT,
allowNull: false,
},
status: {
type: Types.TEXT,
allowNull: false,
defaultValue: 'pending',
},
meta: {
type: Types.JSONB,
defaultValue: {},
allowNull: false,
},
created_at: {
type: Types.DATE,
defaultValue: Types.fn('now'),
allowNull: false,
},
updated_at: {
type: Types.DATE,
defaultValue: Types.fn('now'),
allowNull: false,
},
deleted_at: {
type: Types.DATE,
defaultValue: null,
allowNull: true,
},
})
},
down: (migration, Types) => {
return migration.dropTable('')
},
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"exec:env": "docker-compose -p jetenv up", "exec:env": "docker-compose -p jetenv up",
"exec:ngrok": "ngrok http 7124 --hostname trash.4l2.uk", "exec:ngrok": "ngrok http 7124 --hostname trash.4l2.uk",
"exec:check_img": "NODE_PATH=src node scripts/exec-boot 'node scripts/check_img.js'", "exec:check_img": "NODE_PATH=src node scripts/exec-boot 'node scripts/check_img.js'",
"exec:populate_roots": "NODE_PATH=src node scripts/exec-boot 'node scripts/populate_roots.js'",
"test": "NODE_ENV=testing NODE_PATH=src node scripts/jest.js", "test": "NODE_ENV=testing NODE_PATH=src node scripts/jest.js",
"start": "NODE_PATH=src node server", "start": "NODE_PATH=src node server",
"cmd": "NODE_PATH=src node run", "cmd": "NODE_PATH=src node run",
......
const SelectQuery = `select
metrics.id as metric_id,
uploads.id as upload_id,
(metrics.meta->>'image_id')::uuid as image_id,
(regexp_split_to_array(uploads.upload_url, '\\?'::text))[1] as url
from metrics
join uploads on uploads.upload_url like concat('%', metrics.meta ->> 'image_id', '%')
where
metrics.meta -> 'image_id' IS NOT NULL
and uploads.status = 'success'
and not exists(
select classification_roots.metric_id
from classification_roots
where classification_roots.metric_id = metrics.id
)
limit 20;`
const InsertQuery = `insert into
classification_roots(metric_id, upload_id, image_id, url)
${ SelectQuery }
`
async function main() {
const { sequelize } = require('database/models')
let totalCount = 0
let lastCount = 0
do {
const [_, inserted] = await sequelize.query(InsertQuery, { raw: true })
lastCount = inserted
totalCount += inserted
console.log("Inserted %d entries", lastCount)
await new Promise(r => setTimeout(r, 250))
} while (lastCount > 0)
console.log("Created %d New Roots", totalCount)
process.exit(0)
}
main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment