Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Labels
Plan
Issues
25
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cokoapps
server
Commits
4267df92
Commit
4267df92
authored
2 years ago
by
Alexandros Georgantas
Browse files
Options
Downloads
Patches
Plain Diff
fix(models): improvments in file migration script
parent
2fb8ec87
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!52
Docx
,
!43
fix(models): improvments in file migration script
,
!17
Graphql api
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/models/file/file.model.js
+2
-1
2 additions, 1 deletion
src/models/file/file.model.js
src/models/file/migrations/1638357830-init-file.js
+99
-16
99 additions, 16 deletions
src/models/file/migrations/1638357830-init-file.js
with
101 additions
and
17 deletions
src/models/file/file.model.js
+
2
−
1
View file @
4267df92
...
...
@@ -110,7 +110,8 @@ class File extends BaseModel {
const
{
trx
}
=
options
return
useTransaction
(
async
tr
=>
{
return
File
.
query
(
tr
).
where
({
objectId
})
const
{
result
:
files
}
=
await
File
.
find
({
objectId
},
options
)
return
files
},
{
trx
,
passedTrxOnly
:
true
},
)
...
...
This diff is collapsed.
Click to expand it.
src/models/file/migrations/1638357830-init-file.js
+
99
−
16
View file @
4267df92
...
...
@@ -3,23 +3,106 @@ const logger = require('@pubsweet/logger')
exports
.
up
=
async
knex
=>
{
try
{
return
knex
.
schema
.
createTable
(
'
files
'
,
table
=>
{
table
.
uuid
(
'
id
'
).
primary
()
table
.
timestamp
(
'
created
'
,
{
useTz
:
true
})
.
notNullable
()
.
defaultTo
(
knex
.
fn
.
now
())
table
.
timestamp
(
'
updated
'
,
{
useTz
:
true
})
table
.
text
(
'
type
'
).
notNullable
()
table
.
text
(
'
name
'
).
notNullable
()
table
.
jsonb
(
'
storedObjects
'
).
notNullable
()
table
.
jsonb
(
'
tags
'
).
defaultTo
([])
table
.
uuid
(
'
referenceId
'
).
nullable
()
table
.
uuid
(
'
objectId
'
).
nullable
()
table
.
text
(
'
alt
'
).
nullable
()
table
.
text
(
'
uploadStatus
'
).
nullable
()
table
.
text
(
'
caption
'
).
nullable
()
const
tableExists
=
await
knex
.
schema
.
hasTable
(
'
files
'
)
if
(
!
tableExists
)
{
await
knex
.
schema
.
createTable
(
'
files
'
,
table
=>
{
table
.
uuid
(
'
id
'
).
primary
()
table
.
timestamp
(
'
created
'
,
{
useTz
:
true
})
.
notNullable
()
.
defaultTo
(
knex
.
fn
.
now
())
table
.
timestamp
(
'
updated
'
,
{
useTz
:
true
})
table
.
text
(
'
type
'
).
notNullable
()
table
.
text
(
'
name
'
).
notNullable
()
table
.
jsonb
(
'
storedObjects
'
).
notNullable
()
table
.
jsonb
(
'
tags
'
).
defaultTo
([])
table
.
uuid
(
'
referenceId
'
).
nullable
()
table
.
uuid
(
'
objectId
'
).
nullable
()
table
.
text
(
'
alt
'
).
nullable
()
table
.
text
(
'
uploadStatus
'
).
nullable
()
table
.
text
(
'
caption
'
).
nullable
()
})
return
true
}
const
hasId
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
id
'
)
const
hasCreated
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
created
'
)
const
hasUpdated
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
updated
'
)
const
hasType
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
type
'
)
const
hasName
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
name
'
)
const
hasStoredObjects
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
stored_objects
'
,
)
const
hasTags
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
tags
'
)
const
hasReferenceId
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
reference_id
'
)
const
hasObjectId
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
object_id
'
)
const
hasAlt
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
alt
'
)
const
hasUploadStatus
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
upload_status
'
,
)
const
hasCaption
=
await
knex
.
schema
.
hasColumn
(
'
files
'
,
'
caption
'
)
await
knex
.
schema
.
alterTable
(
'
files
'
,
table
=>
{
if
(
!
hasId
)
{
table
.
dropPrimary
(
'
files_pkey
'
)
table
.
uuid
(
'
id
'
).
primary
()
}
if
(
!
hasCreated
)
{
table
.
timestamp
(
'
created
'
,
{
useTz
:
true
})
.
notNullable
()
.
defaultTo
(
knex
.
fn
.
now
())
}
if
(
!
hasUpdated
)
{
table
.
timestamp
(
'
updated
'
,
{
useTz
:
true
})
}
if
(
!
hasType
)
{
table
.
text
(
'
type
'
).
notNullable
()
}
if
(
!
hasName
)
{
table
.
text
(
'
name
'
).
notNullable
()
}
if
(
!
hasStoredObjects
)
{
table
.
jsonb
(
'
storedObjects
'
).
notNullable
()
}
if
(
!
hasTags
)
{
table
.
jsonb
(
'
tags
'
).
defaultTo
([])
}
if
(
!
hasReferenceId
)
{
table
.
uuid
(
'
referenceId
'
).
nullable
()
}
if
(
!
hasObjectId
)
{
table
.
uuid
(
'
objectId
'
).
nullable
()
}
if
(
!
hasAlt
)
{
table
.
text
(
'
alt
'
).
nullable
()
}
if
(
!
hasUploadStatus
)
{
table
.
text
(
'
uploadStatus
'
).
nullable
()
}
if
(
!
hasCaption
)
{
table
.
text
(
'
caption
'
).
nullable
()
}
})
return
true
}
catch
(
e
)
{
logger
.
error
(
'
File: Initial: Migration failed!
'
)
throw
new
Error
(
e
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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