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

Multi-tenancy #159

Merged
merged 19 commits into from Aug 27, 2021
Merged

Multi-tenancy #159

merged 19 commits into from Aug 27, 2021

Conversation

create-issue-branch[bot]
Copy link
Contributor

@create-issue-branch create-issue-branch bot commented Aug 11, 2021

closes #158

  • Adds an account table and links users and generic assets to it.
  • adds CLI tasks to add/delete accounts
  • many small items coming from this change, e.g. in the UI

Upgrading the database

Verify that the current revision is b6d49ed7cceb or higher before checking out this branch.

The upgrade should be straightforward:

flexmeasures db upgrade

This will:

  • Make sure each user has an account, creating new accounts based on their email address domain.
  • drop generic_asset.owner_id associations (and move them to generic_asset.account_id, using the accounts from step 1). This will be backed up locally, should you want to db downgrade later.

Note:

You can add custom user-account relationships, e.g.:

flexmeasures db upgrade +1 -x '{"1": "Seita", "3": "CustomerA", "30": "CustomerB"}'  

This would associate users 1, 3 and 30 to accounts with the names "Seita", "CustomerA" and "CustomerB", respectively, creating these accounts on the go.

@nhoening
Copy link
Contributor

@nhoening nhoening commented Aug 15, 2021

To be discussed: Can sensors be orphans? I.e. when we delete a GenericAsset, should assorted sensors be deleted automatically? For now, I found code that suggests so and followed through.

@nhoening nhoening marked this pull request as ready for review Aug 17, 2021
@nhoening nhoening requested a review from Flix6x Aug 17, 2021
Copy link
Contributor

@Flix6x Flix6x left a comment

Mostly I just request some documentation, and a short Marshmallow validator for account_id. I also found one or two potential small issues.

Concerning the cascading deletion of sensors and their data, rather than keeping around orphaned data, the way you implemented it here is in line with my preference. That said, I'd recommend being more explicit about the effects of deleting an account.

documentation/getting-started.rst Outdated Show resolved Hide resolved
flexmeasures/conftest.py Outdated Show resolved Hide resolved
documentation/cli/change_log.rst Show resolved Hide resolved
flexmeasures/data/models/user.py Show resolved Hide resolved
flexmeasures/data/schemas/generic_assets.py Outdated Show resolved Hide resolved
flexmeasures/data/scripts/visualize_data_model.py Outdated Show resolved Hide resolved
flexmeasures/data/services/users.py Outdated Show resolved Hide resolved
flexmeasures/data/services/users.py Show resolved Hide resolved
flexmeasures/ui/templates/crud/users.html Show resolved Hide resolved
flexmeasures/data/scripts/cli_tasks/data_delete.py Outdated Show resolved Hide resolved
@nhoening nhoening force-pushed the issue-158-Multi-tenancy branch from c1ef6ea to b95811f Compare Aug 26, 2021
@nhoening
Copy link
Contributor

@nhoening nhoening commented Aug 26, 2021

I re-based this PR on main (should make it easier to view changes) and fixed a few small things.

@nhoening nhoening requested a review from Flix6x Aug 26, 2021
Flix6x
Flix6x approved these changes Aug 27, 2021
Copy link
Contributor

@Flix6x Flix6x left a comment

Congratulations on this milestone achievement!

@Flix6x Flix6x added this to the 0.6.0 milestone Aug 27, 2021
@nhoening nhoening merged commit 247c747 into main Aug 27, 2021
2 checks passed
@Flix6x Flix6x deleted the issue-158-Multi-tenancy branch Mar 1, 2022
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.

2 participants