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

Introducing schema revisions #176

Closed
wants to merge 1 commit into from
Closed

Conversation

kaplun
Copy link
Contributor

@kaplun kaplun commented Jun 16, 2017

Closes #9, Closes #10
Signed-off-by: Samuele Kaplun [email protected]

@kaplun
Copy link
Contributor Author

kaplun commented Jun 16, 2017

@jacquerie @michamos @david-caro this is an initial proposal (still implementing) for supporting ledgers and revisions. Note this is super WIP

@kaplun kaplun force-pushed the revisions branch 3 times, most recently from f1f7b75 to 6105f28 Compare June 20, 2017 12:55
Signed-off-by: Samuele Kaplun <[email protected]>
@michamos
Copy link
Contributor

new element added in #173


def upgrade(json):
schema, current_revision = get_schema_and_revision(json)
for revision, rule in LEDGERS['schema']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here 'schema' should not be a string but the schema var right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if the versions in the ledger are ordered from smallest to largest. This should probably be tested and either documented or sorted in the right order in this loop.

return latest_revisions


LATEST_SCHEMA_REVISIONS = build_latest_schema_revisions()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a global variable with the info? Can't you just call the function when you need it?

I'm a bit troubled by executing code right on import...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memoizing might be nicer ;)

return json


def first_revision_rule(json):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name them in as strict way? something like upgrade_from_base_to_0.0.1, that might be easier to read/scale than 'first/second/third...'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, we could use descriptive names like: new_foo_field.

assert latest_schema_revisions['journals'] == '0.0.1'


def test_get_schema_and_revision():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good candidate to use pytest.mark.parametrize thingie.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also simplify to

result = utils.get_schema_and_revision('literature-1.2.3.json')
expected = 'literature', '1.2.3'
assert result == expected

instead of unpacking the tuples.

Copy link
Contributor

@michamos michamos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all schemas versions are going to live in the same directory? the documentation generation will need to be amended, otherwise it will be a mess.

LEDGERS = build_ledger()


def upgrade(json):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 'json'? calling rule(json) suggests it is a record, but get_schema_and_revision(json) suggests that it is a string instead.


def upgrade(json):
schema, current_revision = get_schema_and_revision(json)
for revision, rule in LEDGERS['schema']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if the versions in the ledger are ordered from smallest to largest. This should probably be tested and either documented or sorted in the right order in this loop.

return json


def first_revision_rule(json):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, we could use descriptive names like: new_foo_field.

assert latest_schema_revisions['journals'] == '0.0.1'


def test_get_schema_and_revision():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also simplify to

result = utils.get_schema_and_revision('literature-1.2.3.json')
expected = 'literature', '1.2.3'
assert result == expected

instead of unpacking the tuples.

@michamos
Copy link
Contributor

BTW, is semver really needed here? if the change is not incompatible, the records don't need to be upgraded.

@kaplun
Copy link
Contributor Author

kaplun commented Nov 6, 2017

@david-caro I think this branch can be considered dead? Has it been decided how to move on with versioning?

@david-caro
Copy link
Contributor

Well, we decided long ago to go with this, but nothing has been done so far (that I know of)

@michamos
Copy link
Contributor

michamos commented Nov 6, 2017

I think @jmartinm wanted to investigate whether we could use alembic instead for that, but don't know if he ever did.

@jacquerie
Copy link
Contributor

We can close this.

@jacquerie jacquerie closed this May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants