This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Current bucket state model
chime-mu edited this page Oct 24, 2017
·
14 revisions
The purpose of these changes was to make it clear how much money was needed to be available in the group. To do that it was necessary to add information about whether the money contributed to a bucket was paid out or not.
The changes was done in way that did not require changes to all bucket records in the database.
These are the states a bucket can be in:
-
Idea - New bucket. Only used for discussion at this point. The target is not fixed yet.
status == 'draft'
-
archived_at
not set. - It can transition to Funding or Cancelled.
- No contributions should exist.
-
Funding - People can start contributing to the bucket. The bucket is not yet fully funded and not cancelled.
status == 'live'
-
archived_at
not set. - It can transition to Funded or Cancelled.
- Contributions can exist.
-
target
is now fixed and can’t be changed. - If a
contribution
is added that makes the sum of contribution go overtarget
, it will be adjusted down. Thus no buckets should have contributions that are overtarget
. This is an invariant. - If a contribution is added that makes the sum of contributions equal to
target
thestatus
get set tofunded
-
Funded - The bucket is fully funded. It’s not completed and it's not cancelled.
status == 'funded'
-
paid_at
not set. - It can transition to Completed or Cancelled.
- Contributions can exist.
-
archived_at
can be set or not. Ifarchived_at
is set, it means the bucket was Archived in the old state model.
-
Completed - The bucket is funded and the money has been paid. It's less visible on the group page.
status == 'funded'
-
paid_at
is set. - There's no transition out of this state.
- Contributions can exist.
-
archived_at
can be set or not. Ifarchived_at
is set, it means the bucket was Archived in the old state model.
-
Cancelled - The bucket is cancelled. It’s not possible to contribute to it. Any previous contributions has been deleted. It’s less visible on the group page.
-
archived_at
is set. -
paid_at
is not set. (status == 'draft') || (status == 'live') || (status == 'refunded')
- There's no transition out of this state.
- No contributions should exist.
-
Old state | New state | Comments |
---|---|---|
Idea | Idea | |
Funding | Funding | |
Funded | Funded |
paid_at is null at creation, so it stays in the same state |
Archived | Funded | We're just ignoring archived_at since we know it's not cancelled |
Cancelled | Cancelled |
paid_at is null. Old Archived buckets that get's cancelled set status = 'refunded'
|
We create a bit vector. The elements are status
, if archived_at
is set and if paid_at
is set.
We set the values of status
to:
status |
Decimal value | Binary value |
---|---|---|
draft |
0 | 00 |
live |
1 | 01 |
funded |
2 | 10 |
refunded |
3 | 11 |
For archived_at
and paid_at
we define a value of 1 if it's set and 0 if it's not set.
We define the bit-vector: <status
2 bits><archived_at
1 bit><paid_at
1 bit>. 4 bits in total giving it values between 0 and 15.
The states then become:
Decimal vector value | Binary vector value | State | Comment |
---|---|---|---|
0 | 0000 | Idea | |
1 | 0001 | Illegal |
paid_at shouldn't be set if status == 'draft'
|
2 | 0010 | Cancelled | |
3 | 0011 | Illegal |
paid_at shouldn't be set if status == 'draft'
|
4 | 0100 | Funding | |
5 | 0101 | Illegal | ´paid_atshouldn't be set when status == 'live'` |
6 | 0110 | Cancelled | |
7 | 0111 | Illegal | ´paid_atshouldn't be set when status == 'live'` |
8 | 1000 | Funded | Ignoring archived_at
|
9 | 1001 | Completed | Ignoring archived_at
|
10 | 1010 | Funded | Ignoring archived_at
|
11 | 1011 | Completed | Ignoring archived_at
|
12 | 1100 | Illegal |
archived_at should be set when status == 'refunded'
|
13 | 1101 | Illegal |
paid_at should not be set when status == 'refunded'
|
14 | 1110 | Cancelled | |
15 | 1111 | Illegal |
paid_at should not be set when status == 'refunded'
|