-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from GSA/harvest-db-update
Harvest db update
- Loading branch information
Showing
33 changed files
with
843 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ tmp/ | |
# vscode debugger | ||
.vscode/ | ||
.env | ||
requirements.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from flask import Flask | ||
from .models import db | ||
from flask_migrate import Migrate | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
DATABASE_URI = os.getenv('DATABASE_URI') | ||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI | ||
db.init_app(app) | ||
|
||
# Initialize Flask-Migrate | ||
Migrate(app, db) | ||
|
||
from .routes import register_routes | ||
register_routes(app) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DATAGOV-HARVESTING-LOGIC | ||
├── app/ | ||
│ ├── __init__.py | ||
│ ├── models.py | ||
│ ├── routes.py | ||
│ ├── forms.py (to-do) | ||
│ └── templates/ | ||
│ ├── index.html | ||
│ ├── harvest_source_form.html (to-do) | ||
│ └── xxx.html (to-do) | ||
│ └── static/ | ||
│ └── styles.css (to-do) | ||
│ | ||
├── migrations/ | ||
│ └── versions/ | ||
│ ├── alembic.ini | ||
│ ├── env.py | ||
│ └── script.py.mako | ||
│ | ||
├── docker-compose.yml | ||
├── Dockerfile | ||
└── run.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
from sqlalchemy.dialects.postgresql import UUID, ARRAY | ||
from sqlalchemy.sql import text | ||
from sqlalchemy import Enum | ||
from sqlalchemy.schema import UniqueConstraint | ||
|
||
db = SQLAlchemy() | ||
|
||
class Base(db.Model): | ||
__abstract__ = True # Indicates that this class should not be created as a table | ||
id = db.Column(UUID(as_uuid=True), primary_key=True, | ||
server_default=text("gen_random_uuid()")) | ||
|
||
class Organization(Base): | ||
__tablename__ = 'organization' | ||
|
||
name = db.Column(db.String(), nullable=False, index=True) | ||
logo = db.Column(db.String()) | ||
|
||
class HarvestSource(Base): | ||
__tablename__ = 'harvest_source' | ||
|
||
name = db.Column(db.String, nullable=False) | ||
notification_emails = db.Column(ARRAY(db.String)) | ||
organization_id = db.Column(UUID(as_uuid=True), | ||
db.ForeignKey('organization.id'), | ||
nullable=False) | ||
frequency = db.Column(db.String, nullable=False) | ||
url = db.Column(db.String, nullable=False, unique=True) | ||
schema_type = db.Column(db.String, nullable=False) | ||
source_type = db.Column(db.String, nullable=False) | ||
jobs = db.relationship('HarvestJob', backref='source') | ||
|
||
class HarvestJob(Base): | ||
__tablename__ = 'harvest_job' | ||
|
||
harvest_source_id = db.Column(UUID(as_uuid=True), | ||
db.ForeignKey('harvest_source.id'), | ||
nullable=False) | ||
status = db.Column(Enum('new', 'in_progress', 'complete', name='job_status'), | ||
nullable=False, | ||
index=True) | ||
date_created = db.Column(db.DateTime, index=True) | ||
date_finished = db.Column(db.DateTime) | ||
records_added = db.Column(db.Integer) | ||
records_updated = db.Column(db.Integer) | ||
records_deleted = db.Column(db.Integer) | ||
records_errored = db.Column(db.Integer) | ||
records_ignored = db.Column(db.Integer) | ||
errors = db.relationship('HarvestError', backref='job', lazy=True) | ||
|
||
class HarvestError(Base): | ||
__tablename__ = 'harvest_error' | ||
|
||
harvest_job_id = db.Column(UUID(as_uuid=True), | ||
db.ForeignKey('harvest_job.id'), | ||
nullable=False) | ||
harvest_record_id = db.Column(db.String) | ||
# to-do | ||
# harvest_record_id = db.Column(UUID(as_uuid=True), | ||
# db.ForeignKey('harvest_record.id'), | ||
# nullable=True) | ||
date_created = db.Column(db.DateTime) | ||
type = db.Column(db.String) | ||
severity = db.Column(Enum('CRITICAL', 'ERROR', 'WARN', name='error_serverity'), | ||
nullable=False, | ||
index=True) | ||
message = db.Column(db.String) | ||
|
||
class HarvestRecord(Base): | ||
__tablename__ = 'harvest_record' | ||
|
||
job_id = db.Column(UUID(as_uuid=True), | ||
db.ForeignKey('harvest_job.id'), | ||
nullable=False) | ||
identifier = db.Column(db.String(), nullable=False) | ||
ckan_id = db.Column(db.String(), nullable=False, index=True) | ||
type = db.Column(db.String(), nullable=False) | ||
source_metadata = db.Column(db.String(), nullable=True) | ||
__table_args__ = ( | ||
UniqueConstraint('job_id', 'identifier', name='uix_job_id_identifier'), | ||
) |
Oops, something went wrong.
f60156a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report