Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Jetsam Server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jetsam
Jetsam Server
Commits
166ad559
Verified
Commit
166ad559
authored
3 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Create classification_roots table
parent
00e6c0b3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
database/migrations/20211208000001-create-classification-roots-table.js
+57
-0
57 additions, 0 deletions
...tions/20211208000001-create-classification-roots-table.js
package.json
+1
-0
1 addition, 0 deletions
package.json
scripts/populate_roots.js
+42
-0
42 additions, 0 deletions
scripts/populate_roots.js
with
100 additions
and
0 deletions
database/migrations/20211208000001-create-classification-roots-table.js
0 → 100644
+
57
−
0
View file @
166ad559
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
This diff is collapsed.
Click to expand it.
package.json
+
1
−
0
View file @
166ad559
...
@@ -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"
,
...
...
This diff is collapsed.
Click to expand it.
scripts/populate_roots.js
0 → 100644
+
42
−
0
View file @
166ad559
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment