add email subscription table

This commit is contained in:
knst-kotov 2022-06-04 09:34:19 +03:00
parent 6f2973c1b1
commit 9558a1afaa
3 changed files with 27 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import re
import frontmatter import frontmatter
from migration.tables.users import migrate as migrateUser from migration.tables.users import migrate as migrateUser
from migration.tables.users import migrate_2stage as migrateUser_2stage from migration.tables.users import migrate_2stage as migrateUser_2stage
from migration.tables.users import migrate_email_subscription
from migration.tables.content_items import get_metadata, migrate as migrateShout from migration.tables.content_items import get_metadata, migrate as migrateShout
from migration.tables.content_item_categories import migrate as migrateCategory from migration.tables.content_item_categories import migrate as migrateCategory
from migration.tables.tags import migrate as migrateTag from migration.tables.tags import migrate as migrateTag
@ -194,6 +195,11 @@ def comments(comments_data):
migrateComment_2stage(comment, id_map) migrateComment_2stage(comment, id_map)
print(str(len(id_map)) + ' comments exported') print(str(len(id_map)) + ' comments exported')
def export_email_subscriptions(email_subscriptions_data):
for data in email_subscriptions_data:
migrate_email_subscription(data)
print(str(len(email_subscriptions_data)) + ' email subscriptions exported')
def export_finish(export_articles = {}, export_authors = {}, export_topics = {}, export_comments = {}): def export_finish(export_articles = {}, export_authors = {}, export_topics = {}, export_comments = {}):
open('../src/data/authors.json', 'w').write(json.dumps(export_authors, open('../src/data/authors.json', 'w').write(json.dumps(export_authors,
@ -274,6 +280,9 @@ if __name__ == '__main__':
comments_by_post[cid].append(old_comment) comments_by_post[cid].append(old_comment)
print(str(len(comments_by_post.keys())) + ' articles with comments') print(str(len(comments_by_post.keys())) + ' articles with comments')
email_subscriptions_data = json.loads(open('migration/data/email_subscriptions.json').read())
print(str(len(email_subscriptions_data)) + ' email subscriptions loaded')
export_articles = {} # slug: shout export_articles = {} # slug: shout
export_authors = {} # slug: user export_authors = {} # slug: user
export_comments = {} # shout-slug: comment[] (list) export_comments = {} # shout-slug: comment[] (list)
@ -291,11 +300,14 @@ if __name__ == '__main__':
comments(comments_data) comments(comments_data)
elif cmd == "export_shouts": elif cmd == "export_shouts":
export_shouts(shouts_by_slug, export_articles, export_authors, content_dict) export_shouts(shouts_by_slug, export_articles, export_authors, content_dict)
elif cmd == "email_subscriptions":
export_email_subscriptions(email_subscriptions_data)
elif cmd == "all": elif cmd == "all":
users(users_by_oid, users_by_slug, users_data) users(users_by_oid, users_by_slug, users_data)
topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data) topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data)
shouts(content_data, shouts_by_slug, shouts_by_oid) shouts(content_data, shouts_by_slug, shouts_by_oid)
comments(comments_data) comments(comments_data)
export_email_subscriptions(email_subscriptions_data)
elif cmd == 'slug': elif cmd == 'slug':
export_slug(sys.argv[2], export_articles, export_authors, content_dict) export_slug(sys.argv[2], export_articles, export_authors, content_dict)
#export_finish(export_articles, export_authors, export_topics, export_comments) #export_finish(export_articles, export_authors, export_topics, export_comments)

View File

@ -1,4 +1,5 @@
from orm import User, Role, UserRating from orm import User, Role, UserRating
from orm.user import EmailSubscription
import frontmatter import frontmatter
from dateutil.parser import parse from dateutil.parser import parse
from migration.html2text import html2text from migration.html2text import html2text
@ -88,6 +89,13 @@ def migrate(entry):
return res return res
def migrate_email_subscription(entry):
res = {}
res["email"] = entry["email"]
res["createdAt"] = parse(entry["createdAt"])
subscription = EmailSubscription.create(**res)
def migrate_2stage(entry, id_map): def migrate_2stage(entry, id_map):
for rating_entry in entry.get('ratings',[]): for rating_entry in entry.get('ratings',[]):
rater_old_id = rating_entry['createdBy'] rater_old_id = rating_entry['createdBy']

View File

@ -41,6 +41,13 @@ class AuthorSubscription(Base):
author = Column(ForeignKey('user.slug'), primary_key = True) author = Column(ForeignKey('user.slug'), primary_key = True)
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
class EmailSubscription(Base):
__tablename__ = "email_subscription"
id = None
email = Column(String, primary_key = True)
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
class User(Base): class User(Base):
__tablename__ = "user" __tablename__ = "user"