Преглед изворни кода

more database changes: new database structure

joel
Simon Bowie пре 2 година
родитељ
комит
d89e92d6e1
2 измењених фајлова са 117 додато и 20 уклоњено
  1. +110
    -12
      web/app/models.py
  2. +7
    -8
      web/app/tool.py

+ 110
- 12
web/app/models.py Прегледај датотеку

@@ -13,6 +13,8 @@ from datetime import datetime

# table for users
class User(UserMixin, db.Model):
__tablename__ = 'User'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
email = db.Column(db.String(100), unique=True)
password = db.Column(db.String(100))
@@ -20,30 +22,126 @@ class User(UserMixin, db.Model):

# table for tools
class Tool(db.Model):
__tablename__ = 'Tool'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)
project_url = db.Column(db.Text)
repository_url = db.Column(db.Text)
platform_status = db.Column(db.Text)
expertise = db.Column(db.Text)
self_host_expertise = db.Column(db.Text)
ingest = db.Column(db.Text)
output = db.Column(db.Text)
saas = db.Column(db.Text)
projectUrl = db.Column(db.Text)
repositoryUrl = db.Column(db.Text)
expertiseToUse = db.Column(db.Text)
expertiseToHost = db.Column(db.Text)
dependencies = db.Column(db.Text)
ingestFormats = db.Column(db.Text)
outputFormats = db.Column(db.Text)
status = db.Column(db.Text)

practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))

practices = db.relationship('Practice', foreign_keys=[practice_id], backref='tool')
books = db.relationship('Book', foreign_keys=[book_id], backref='tool')

# table for practices
class Practice(db.Model):
__tablename__ = 'Practice'

# table for books
class Book(db.Model):
id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)

# table for examples
class Practice(db.Model):
tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))

tools = db.relationship('Tool', foreign_keys=[tool_id], backref='practice')
typologies = db.relationship('Typology', foreign_keys=[typology_id], backref='practice')
books = db.relationship('Book', foreign_keys=[book_id], backref='practice')
references = db.relationship('Reference', foreign_keys=[reference_id], backref='practice')

# table for sensitivities
class Sensitivity(db.Model):
__tablename__ = 'Sensitivity'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)

practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))

practices = db.relationship('Practice', foreign_keys=[practice_id], backref='sensitivity')
typologies = db.relationship('Typology', foreign_keys=[typology_id], backref='sensitivity')
references = db.relationship('Reference', foreign_keys=[reference_id], backref='sensitivity')

# table for typologies
class Typology(db.Model):
__tablename__ = 'Typology'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)

tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))

tools = db.relationship('Tool', foreign_keys=[tool_id], backref='typology')
books = db.relationship('Book', foreign_keys=[book_id], backref='typology_books')
practices = db.relationship('Practice', foreign_keys=[practice_id], backref='typology')
references = db.relationship('Reference', foreign_keys=[reference_id], backref='typology')

# table for workflows
class Workflow(db.Model):
__tablename__ = 'Workflow'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)

# table for publishers
class Publisher(db.Model):
__tablename__ = 'Publisher'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)
publisherUrl = db.Column(db.Text)

book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))

books = db.relationship('Book', foreign_keys=[book_id], backref='publisher')

# table for books
class Book(db.Model):
__tablename__ = 'Book'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
name = db.Column(db.Text)
description = db.Column(db.Text)

tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
workflow_id = db.Column(db.Integer, db.ForeignKey('Workflow.id'))

tools = db.relationship('Tool', foreign_keys=[tool_id], backref='book')
typology = db.relationship('Typology', foreign_keys=[typology_id], backref='book')
practices = db.relationship('Practice', foreign_keys=[practice_id], backref='book')
workflow = db.relationship('Workflow', foreign_keys=[workflow_id], backref='book')

# table for references
class Reference(db.Model):
__tablename__ = 'Reference'

id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
created = db.Column(db.DateTime, default=datetime.utcnow)
zoteroUrl = db.Column(db.Text)

+ 7
- 8
web/app/tool.py Прегледај датотеку

@@ -50,15 +50,14 @@ def edit_tool(tool_id):
tool = Tool.query.get(tool_id)
tool.name = name
tool.description = description
tool.project_url = project_url
tool.repository_url = repository_url
tool.platform_status = platform_status
tool.expertise = expertise
tool.self_host_expertise = self_host_expertise
tool.ingest = ingest
tool.output = output
tool.saas = saas
tool.projectUrl = project_url
tool.repositoryUrl = repository_url
tool.dependencies = dependencies
tool.expertiseToUse = expertise
tool.expertiseToHost = self_host_expertise
tool.ingestFormats = ingest
tool.outputFormats = output
tool.status = status
db.session.commit()
return redirect(url_for('tool.get_tools'))


Loading…
Откажи
Сачувај