Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize Sources #24

Open
bbengfort opened this issue Apr 12, 2015 · 2 comments
Open

Generalize Sources #24

bbengfort opened this issue Apr 12, 2015 · 2 comments

Comments

@bbengfort
Copy link
Owner

Right now the sources that are allowed (CPS, CESN) and disallowed (LAUS, CESSM) are hardcoded into the SourcesView object for the API.

Allowed sources are short enough to give all data to the app, disallowed sources (with state contexts) are too long to give an entire data set from.

We need to generalize the sources such that the database determines if the source is allowed or not. E.g. by creating a sources model.

Note that any source not found in the hardcoded sets is simply a 404.

@bbengfort
Copy link
Owner Author

Here is the model:

class Source(db.Model):
    """
    Stores information about data sources from the BLS API
    """

    __tablename__ = "source"

    id          = db.Column(db.Integer, primary_key=True)
    name        = db.Column(db.Unicode(255), unique=True, index=True)
    description = db.Column(db.Unicode(255), nullable=True)
    series      = db.relationship('Series', backref='source', lazy='dynamic')


class Series(db.Model):
    """
    Stores information about TimeSeries data on the BLS API
    """

    __tablename__ = "series"

    id          = db.Column(db.Integer, primary_key=True)
    blsid       = db.Column(db.Unicode(255), unique=True, index=True)
    title       = db.Column(db.Unicode(255), nullable=True)
    source_id   = db.Column(db.Integer, db.ForeignKey('source.id'))
    is_primary  = db.Column(db.Boolean, default=False)
    records     = db.relationship('SeriesRecord', backref='series',
                                  lazy='dynamic')

    def __repr__(self):
        return "<Series %s>" % self.blsid

@bbengfort
Copy link
Owner Author

For the migrations:

  • create SQL migrations in the migrate folder
  • update should alter the table, insert distinct sources, update all columns, then alter table
  • downgrade should drop the cps table and do reverse alterations

@bbengfort bbengfort modified the milestones: v0.4.0, v0.5.0 Apr 15, 2015
@bbengfort bbengfort removed this from the v0.5.0 milestone May 3, 2015
@bbengfort bbengfort removed the ready label May 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant