Merge
This commit is contained in:
commit
de6d4c47a3
21
migrate.py
21
migrate.py
|
@ -9,14 +9,14 @@ def users():
|
||||||
data = json.loads(open('migration/data/users.json').read())
|
data = json.loads(open('migration/data/users.json').read())
|
||||||
newdata = {}
|
newdata = {}
|
||||||
counter = 0
|
counter = 0
|
||||||
try:
|
#try:
|
||||||
for entry in data:
|
for entry in data:
|
||||||
oid = entry['_id']
|
oid = entry['_id']
|
||||||
newdata[oid] = migrateUser(entry)
|
newdata[oid] = migrateUser(entry)
|
||||||
counter += 1
|
counter += 1
|
||||||
except Exception:
|
#except Exception:
|
||||||
print(str(counter) + '/' + str(len(data)) + ' users entries were migrated')
|
# print(str(counter) + '/' + str(len(data)) + ' users entries were migrated')
|
||||||
print('try to remove database first')
|
# print('try to remove database first')
|
||||||
open('migration/data/users.dict.json','w').write( json.dumps(newdata, cls=DateTimeEncoder) )
|
open('migration/data/users.dict.json','w').write( json.dumps(newdata, cls=DateTimeEncoder) )
|
||||||
print(str(counter) + ' users entries were migrated')
|
print(str(counter) + ' users entries were migrated')
|
||||||
|
|
||||||
|
@ -47,7 +47,10 @@ def shouts():
|
||||||
oid = entry['_id']
|
oid = entry['_id']
|
||||||
newdata[oid] = migrateShout(entry)
|
newdata[oid] = migrateShout(entry)
|
||||||
counter += 1
|
counter += 1
|
||||||
|
print(str(counter) + ': ' + newdata['slug'])
|
||||||
|
if counter > 9:
|
||||||
|
break
|
||||||
|
|
||||||
open('migration/data/shouts.dict.json','w').write( json.dumps(newdata, cls=DateTimeEncoder) )
|
open('migration/data/shouts.dict.json','w').write( json.dumps(newdata, cls=DateTimeEncoder) )
|
||||||
print(str(counter) + ' shouts were migrated')
|
print(str(counter) + ' shouts were migrated')
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,6 @@ def migrate(entry):
|
||||||
'org': 'discours.io',
|
'org': 'discours.io',
|
||||||
'slug': entry['slug'],
|
'slug': entry['slug'],
|
||||||
'createdAt': entry['createdAt'],
|
'createdAt': entry['createdAt'],
|
||||||
'body': markdown(entry['body']),
|
'body': markdown.feed(entry['body']),
|
||||||
'replyTo': entry['']
|
'replyTo': entry['']
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
def migrate(entry):
|
def migrate(entry):
|
||||||
```
|
'''
|
||||||
type Topic {
|
type Topic {
|
||||||
slug: String! # ID
|
slug: String! # ID
|
||||||
createdBy: Int! # User
|
createdBy: Int! # User
|
||||||
|
@ -8,12 +8,13 @@ def migrate(entry):
|
||||||
parents: [String] # NOTE: topic can have parent topics
|
parents: [String] # NOTE: topic can have parent topics
|
||||||
children: [String] # and children
|
children: [String] # and children
|
||||||
}
|
}
|
||||||
```
|
'''
|
||||||
return {
|
return {
|
||||||
'slug': entry['slug'],
|
'slug': entry['slug'],
|
||||||
'createdBy': entry['createdBy'], # NOTE: uses an old user id
|
'createdBy': entry['createdBy'], # NOTE: uses an old user id
|
||||||
'createdAt': entry['createdAt'],
|
'createdAt': entry['createdAt'],
|
||||||
'value': entry['title'].lower(),
|
'value': entry['title'].lower(),
|
||||||
'parents': [],
|
'parents': [],
|
||||||
'children': []
|
'children': [],
|
||||||
|
'old_id': entry['_id']
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
from migration.html2md import Converter
|
from migration.html2md import Converter
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
import frontmatter
|
||||||
import json
|
import json
|
||||||
from orm import Shout
|
from orm import Shout
|
||||||
|
|
||||||
|
@ -70,15 +71,20 @@ def migrate(entry):
|
||||||
if entry.get('updatedAt') is not None:
|
if entry.get('updatedAt') is not None:
|
||||||
r['updatedAt'] = entry['updatedAt']
|
r['updatedAt'] = entry['updatedAt']
|
||||||
if entry.get('type') == 'Literature':
|
if entry.get('type') == 'Literature':
|
||||||
r['body'] = entry['media'][0]['literatureBody']
|
r['body'] = markdown.feed(entry['media'][0]['literatureBody'])
|
||||||
elif entry.get('type') == 'Video':
|
elif entry.get('type') == 'Video':
|
||||||
r['body'] = '<ShoutVideo src=\"' + entry['media'][0]['youtubeId'] + '\" />'
|
r['body'] = '<ShoutVideo src=\"' + entry['media'][0]['youtubeId'] + '\" />'
|
||||||
elif entry.get('type') == 'Music':
|
elif entry.get('type') == 'Music':
|
||||||
r['body'] = '<ShoutMusic media={\"' + json.dumps(entry['media']) +'\"} />'
|
r['body'] = '<ShoutMusic media={\"' + json.dumps(entry['media']) +'\"} />'
|
||||||
|
elif entry.get('body') is not None:
|
||||||
|
r['body'] = markdown.feed(entry['body'])
|
||||||
else:
|
else:
|
||||||
r['body'] = '## ' + r['title']
|
r['body'] = '## ' + r['title']
|
||||||
# TODO: compile md with graymatter
|
body = r['body']
|
||||||
open('migration/content/' + r['slug'] + '.md', 'w').write(mdfile)
|
del r['body']
|
||||||
|
metadata = frontmatter.dumps(r)
|
||||||
|
open('migration/content/' + r['slug'] + '.md', 'w').write(metadata + '\n' + body)
|
||||||
|
r['body'] = body
|
||||||
shout = Shout.create(**r.copy())
|
shout = Shout.create(**r.copy())
|
||||||
r['id'] = shout['id']
|
r['id'] = shout['id']
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from orm import User
|
from orm import User, Role
|
||||||
|
import frontmatter
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
from migration.html2md import Converter
|
||||||
|
markdown = Converter()
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
def migrate(entry):
|
def migrate(entry):
|
||||||
|
@ -30,46 +32,46 @@ def migrate(entry):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
res = {}
|
res = {}
|
||||||
try:
|
res['old_id'] = entry['_id']
|
||||||
res['old_id'] = entry['_id']
|
res['password'] = entry['services']['password'].get('bcrypt', '')
|
||||||
res['password'] = entry['services']['password'].get('bcrypt', '')
|
res['username'] = entry['emails'][0]['address']
|
||||||
res['username'] = entry['emails'][0]['address']
|
res['email'] = res['username']
|
||||||
res['email'] = res['username']
|
res['wasOnlineAt'] = parse(entry.get('loggedInAt', entry['createdAt']))
|
||||||
res['wasOnlineAt'] = parse(entry.get('loggedInAt', entry['createdAt']))
|
res['emailConfirmed'] = entry['emails'][0]['verified']
|
||||||
res['emailConfirmed'] = entry['emails'][0]['verified']
|
res['createdAt'] = parse(entry['createdAt'])
|
||||||
res['createdAt'] = parse(entry['createdAt'])
|
res['rating'] = entry['rating'] # number
|
||||||
res['rating'] = entry['rating'] # number
|
res['roles'] = [] # entry['roles'] # roles without org is for discours.io
|
||||||
res['roles'] = [] # entry['roles'] # roles without org is for discours.io
|
res['ratings'] = [] # entry['ratings']
|
||||||
res['ratings'] = [] # entry['ratings']
|
res['notifications'] = []
|
||||||
res['notifications'] = []
|
res['links'] = []
|
||||||
res['links'] = []
|
res['muted'] = False
|
||||||
res['muted'] = False
|
res['bio'] = markdown.feed(entry.get('bio', ''))
|
||||||
res['viewname'] = 'anonymous'
|
if entry['profile']:
|
||||||
if entry['profile']:
|
res['slug'] = entry['profile'].get('path')
|
||||||
res['slug'] = entry['profile'].get('path')
|
res['userpic'] = entry['profile'].get('image', {'url': ''}).get('url', '')
|
||||||
res['userpic'] = entry['profile'].get('image', {'url': ''}).get('url', '')
|
fn = entry['profile'].get('firstName', '')
|
||||||
viewname = entry['profile'].get('firstName', '') + ' ' + entry['profile'].get('lastName', '')
|
ln = entry['profile'].get('lastName', '')
|
||||||
viewname = entry['profile']['path'] if len(viewname) < 2 else viewname
|
viewname = res['slug'] if res['slug'] else 'anonymous'
|
||||||
res['viewname'] = viewname
|
viewname = fn if fn else viewname
|
||||||
fb = entry['profile'].get('facebook', False)
|
viewname = (viewname + ' ' + ln) if ln else viewname
|
||||||
if fb:
|
viewname = entry['profile']['path'] if len(viewname) < 2 else viewname
|
||||||
res['links'].append(fb)
|
res['viewname'] = viewname
|
||||||
vk = entry['profile'].get('vkontakte', False)
|
fb = entry['profile'].get('facebook', False)
|
||||||
if vk:
|
if fb:
|
||||||
res['links'].append(vk)
|
res['links'].append(fb)
|
||||||
tr = entry['profile'].get('twitter', False)
|
vk = entry['profile'].get('vkontakte', False)
|
||||||
if tr:
|
if vk:
|
||||||
res['links'].append(tr)
|
res['links'].append(vk)
|
||||||
ws = entry['profile'].get('website', False)
|
tr = entry['profile'].get('twitter', False)
|
||||||
if ws:
|
if tr:
|
||||||
res['links'].append(ws)
|
res['links'].append(tr)
|
||||||
if not res['slug']:
|
ws = entry['profile'].get('website', False)
|
||||||
res['slug'] = res['links'][0].split('/')[-1]
|
if ws:
|
||||||
|
res['links'].append(ws)
|
||||||
if not res['slug']:
|
if not res['slug']:
|
||||||
res['slug'] = res['email'].split('@')[0]
|
res['slug'] = res['links'][0].split('/')[-1]
|
||||||
except Exception:
|
if not res['slug']:
|
||||||
print(entry['profile'])
|
res['slug'] = res['email'].split('@')[0]
|
||||||
raise Exception
|
|
||||||
else:
|
else:
|
||||||
old = res['old_id']
|
old = res['old_id']
|
||||||
del res['old_id']
|
del res['old_id']
|
||||||
|
|
|
@ -38,7 +38,7 @@ class User(Base):
|
||||||
userpic: str = Column(String, nullable=True, comment="Userpic")
|
userpic: str = Column(String, nullable=True, comment="Userpic")
|
||||||
viewname: str = Column(String, nullable=True, comment="Display name")
|
viewname: str = Column(String, nullable=True, comment="Display name")
|
||||||
rating: int = Column(Integer, nullable=True, comment="Rating")
|
rating: int = Column(Integer, nullable=True, comment="Rating")
|
||||||
slug: str = Column(String, unique=True, comment="Author's slug")
|
slug: str = Column(String, unique=True, comment="User's slug")
|
||||||
muted: bool = Column(Boolean, default=False)
|
muted: bool = Column(Boolean, default=False)
|
||||||
emailConfirmed: bool = Column(Boolean, default=False)
|
emailConfirmed: bool = Column(Boolean, default=False)
|
||||||
createdAt: DateTime = Column(DateTime, nullable=False, comment="Created at")
|
createdAt: DateTime = Column(DateTime, nullable=False, comment="Created at")
|
||||||
|
|
|
@ -3,72 +3,72 @@ scalar DateTime
|
||||||
################################### Payload
|
################################### Payload
|
||||||
|
|
||||||
type Result {
|
type Result {
|
||||||
error: String
|
error: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthResult {
|
type AuthResult {
|
||||||
error: String
|
error: String
|
||||||
token: String
|
token: String
|
||||||
user: User
|
user: User
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserResult {
|
type UserResult {
|
||||||
error: String
|
error: String
|
||||||
user: User
|
user: User
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageResult {
|
type MessageResult {
|
||||||
error: String
|
error: String
|
||||||
message: Message
|
message: Message
|
||||||
}
|
}
|
||||||
|
|
||||||
input ShoutInput {
|
input ShoutInput {
|
||||||
org_id: Int!
|
org_id: Int!
|
||||||
slug: String!
|
slug: String!
|
||||||
body: String!
|
body: String!
|
||||||
replyTo: String # another shout
|
replyTo: String # another shout
|
||||||
tags: [String] # actual values
|
tags: [String] # actual values
|
||||||
topics: [String] # topic-slugs
|
topics: [String] # topic-slugs
|
||||||
title: String
|
title: String
|
||||||
versionOf: String
|
versionOf: String
|
||||||
visibleForRoles: [String] # role ids are strings
|
visibleForRoles: [String] # role ids are strings
|
||||||
visibleForUsers: [Int]
|
visibleForUsers: [Int]
|
||||||
}
|
}
|
||||||
|
|
||||||
input ProfileInput {
|
input ProfileInput {
|
||||||
email: String
|
email: String
|
||||||
username: String
|
username: String
|
||||||
userpic: String
|
userpic: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShoutResult {
|
type ShoutResult {
|
||||||
error: String
|
error: String
|
||||||
shout: Shout
|
shout: Shout
|
||||||
}
|
}
|
||||||
|
|
||||||
################################### Mutation
|
################################### Mutation
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
# message
|
# message
|
||||||
createMessage(body: String!, replyTo: Int): MessageResult!
|
createMessage(body: String!, replyTo: Int): MessageResult!
|
||||||
updateMessage(id: Int!, body: String!): MessageResult!
|
updateMessage(id: Int!, body: String!): MessageResult!
|
||||||
deleteMessage(messageId: Int!): Result!
|
deleteMessage(messageId: Int!): Result!
|
||||||
|
|
||||||
# auth
|
# auth
|
||||||
confirmEmail(token: String!): AuthResult!
|
confirmEmail(token: String!): AuthResult!
|
||||||
requestPasswordReset(email: String!): Boolean!
|
requestPasswordReset(email: String!): Boolean!
|
||||||
confirmPasswordReset(token: String!): Boolean!
|
confirmPasswordReset(token: String!): Boolean!
|
||||||
registerUser(email: String!, password: String!): AuthResult!
|
registerUser(email: String!, password: String!): AuthResult!
|
||||||
# updatePassword(password: String!, token: String!): Token!
|
# updatePassword(password: String!, token: String!): Token!
|
||||||
# invalidateAllTokens: Boolean!
|
# invalidateAllTokens: Boolean!
|
||||||
# invalidateTokenById(id: Int!): Boolean!
|
# invalidateTokenById(id: Int!): Boolean!
|
||||||
# requestEmailConfirmation: User!
|
# requestEmailConfirmation: User!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
createShout(input: ShoutInput!): ShoutResult!
|
createShout(input: ShoutInput!): ShoutResult!
|
||||||
updateShout(input: ShoutInput!): ShoutResult!
|
updateShout(input: ShoutInput!): ShoutResult!
|
||||||
deleteShout(slug: String!): Result!
|
deleteShout(slug: String!): Result!
|
||||||
rateShout(slug: String!, value: Int!): Result!
|
rateShout(slug: String!, value: Int!): Result!
|
||||||
|
|
||||||
# user profile
|
# user profile
|
||||||
# rateUser(value: Int!): Result!
|
# rateUser(value: Int!): Result!
|
||||||
|
@ -80,11 +80,11 @@ type Mutation {
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
# auth
|
# auth
|
||||||
isEmailFree(email: String!): Result!
|
isEmailFree(email: String!): Result!
|
||||||
signIn(email: String!, password: String!): AuthResult!
|
signIn(email: String!, password: String!): AuthResult!
|
||||||
signOut: Result!
|
signOut: Result!
|
||||||
# user profile
|
# user profile
|
||||||
getCurrentUser: UserResult!
|
getCurrentUser: UserResult!
|
||||||
getUserById(id: Int!): UserResult!
|
getUserById(id: Int!): UserResult!
|
||||||
# getUserRating(shout: Int): Int!
|
# getUserRating(shout: Int): Int!
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ type Query {
|
||||||
# shoutsByTime(time: DateTime): [Shout]!
|
# shoutsByTime(time: DateTime): [Shout]!
|
||||||
|
|
||||||
# getOnlineUsers: [User!]!
|
# getOnlineUsers: [User!]!
|
||||||
topAuthors: [User]!
|
topAuthors: [User]!
|
||||||
topShouts: [Shout]!
|
topShouts: [Shout]!
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################ Subscription
|
############################################ Subscription
|
||||||
|
@ -109,7 +109,7 @@ type Subscription {
|
||||||
messageCreated: Message!
|
messageCreated: Message!
|
||||||
messageUpdated: Message!
|
messageUpdated: Message!
|
||||||
messageDeleted: Message!
|
messageDeleted: Message!
|
||||||
|
|
||||||
onlineUpdated: [User!]!
|
onlineUpdated: [User!]!
|
||||||
shoutUpdated: Shout!
|
shoutUpdated: Shout!
|
||||||
userUpdated: User!
|
userUpdated: User!
|
||||||
|
@ -127,7 +127,7 @@ type Role {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rating {
|
type Rating {
|
||||||
createdBy: String!
|
createdBy: Int!
|
||||||
value: Int!
|
value: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ type User {
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
slug: String
|
slug: String
|
||||||
bio: String
|
bio: String
|
||||||
notifications: [Int]
|
notifications: [Int]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message {
|
type Message {
|
||||||
|
@ -178,25 +178,24 @@ type Message {
|
||||||
|
|
||||||
# is publication
|
# is publication
|
||||||
type Shout {
|
type Shout {
|
||||||
|
org_id: Int!
|
||||||
slug: String!
|
slug: String!
|
||||||
authors: [Int!]!
|
authors: [Int!]!
|
||||||
body: String!
|
|
||||||
org_id: Int
|
|
||||||
cover: String
|
cover: String
|
||||||
layout: String
|
layout: String
|
||||||
|
body: String!
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
updatedAt: DateTime
|
updatedAt: DateTime!
|
||||||
deletedAt: DateTime
|
deletedAt: DateTime
|
||||||
deletedBy: Int
|
deletedBy: Int
|
||||||
rating: Int
|
rating: Int
|
||||||
ratigns: [Rating]
|
ratigns: [Rating]
|
||||||
published: Boolean
|
published: Boolean!
|
||||||
publishedAt: DateTime # if there is no published field - it is not published
|
publishedAt: DateTime # if there is no published field - it is not published
|
||||||
replyTo: String # another shout
|
replyTo: String # another shout
|
||||||
tags: [String] # actual values
|
tags: [String] # actual values
|
||||||
topics: [String] # topic-slugs, order has matter
|
topics: [String] # topic-slugs, order has matter
|
||||||
title: String
|
title: String
|
||||||
subtitle: String
|
|
||||||
versionOf: String
|
versionOf: String
|
||||||
visibleForRoles: [String] # role ids are strings
|
visibleForRoles: [String] # role ids are strings
|
||||||
visibleForUsers: [Int]
|
visibleForUsers: [Int]
|
||||||
|
@ -215,6 +214,7 @@ type Topic {
|
||||||
|
|
||||||
# TODO: resolvers to add/remove topics from publication
|
# TODO: resolvers to add/remove topics from publication
|
||||||
|
|
||||||
|
|
||||||
type Proposal {
|
type Proposal {
|
||||||
body: String!
|
body: String!
|
||||||
shout: Int!
|
shout: Int!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user