Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 4132 Bytes
1 | ######################################################################## |
2 | # File:: 20110130112550_create_payments.rb |
3 | # (C):: Hipposoft 2011 |
4 | # |
5 | # Purpose:: Create or destroy the 'donations' table. |
6 | # ---------------------------------------------------------------------- |
7 | # 30-Jan-2011 (ADH): Created. |
8 | ######################################################################## |
9 | |
10 | class CreateDonations < ActiveRecord::Migration |
11 | def self.up |
12 | create_table :donations do | t | |
13 | |
14 | # There is a link back to the user who made the donation and the poll |
15 | # they donated against. If either the poll or user get deleted in future, |
16 | # important audit trail information about the user is copied into the |
17 | # payment record as a backup. |
18 | |
19 | t.belongs_to :user # => integer user_id |
20 | t.string :user_name, :null => false, :limit => User::MAXLEN_NAME |
21 | t.string :user_email, :null => false, :limit => User::MAXLEN_EMAIL |
22 | |
23 | t.belongs_to :poll # => integer poll_id |
24 | t.string :poll_title, :null => false, :limit => Poll::MAXLEN_TITLE |
25 | |
26 | # Donations must record the currency in case the poll goes away. |
27 | |
28 | t.belongs_to :currency # => integer currency_id |
29 | |
30 | # For the Workflow gem (see config/environment.rb). |
31 | |
32 | t.string :workflow_state, :null => false, :limit => Donation::MAXLEN_STATE |
33 | |
34 | # Some donations arise from redistribution of money from e.g. expired |
35 | # polls and may have negative or positive amounts depending on whether |
36 | # they've been taken from the expired poll or added to an open poll. The |
37 | # "debit" flag indicates the amount removed from the poll that expired, |
38 | # else it's a contribution to a poll which was open. The source poll ID |
39 | # and title is given in the next two parameters. |
40 | t.boolean :redistribution, :default => false |
41 | t.boolean :debit, :default => false |
42 | t.belongs_to :source_poll # => integer source_poll_id |
43 | t.string :source_poll_title, :limit => Poll::MAXLEN_TITLE |
44 | |
45 | # Monotonically rising invoice number, assigned via the InvoiceNumber |
46 | # model mechanism and singleton instance when a purchase is committed. |
47 | |
48 | t.integer :invoice_number |
49 | |
50 | # Some payment gateways let the payer leave a note for the payee. |
51 | |
52 | t.text :notes |
53 | |
54 | # Authorisation tokens are needed in several places. For on-site payments |
55 | # they're used to authorise and capture funds in separate phases which |
56 | # avoids the need to store credit card details locally. Tokens for each |
57 | # currency are pushed into a serialised array. Once funds are captured, |
58 | # the authorisation tokens are stored in a hash keyed by ":onsite", with |
59 | # the value itself a hash keyed by currency ID as a string with values |
60 | # of the actual capture response authorisation tokens. These are used for |
61 | # refunds later if necessary. Off-site payments use a similar hash, keyed |
62 | # by ":offsite", to store the single currency payment transaction details |
63 | # in case of refunds later. |
64 | # |
65 | # The code for this is adapted from Artisan and over-specified for this |
66 | # model, wherein only a single currency and single combined action of |
67 | # donation/voting/purchasing is made, so within Canvass things are often |
68 | # more simple. |
69 | |
70 | t.text :authorisation_tokens |
71 | |
72 | # In Artisan the Purchase model records purchases connected to a series |
73 | # of order items related to shopping cart entries. Each of these carries |
74 | # its cost, so the total purchase value is found from them. In Canvass, |
75 | # just a single payment is made, so the amount is stored here directly. |
76 | # A low accuracy float cache copy is kept for search and sort purposes. |
77 | |
78 | t.string :amount_integer, :null => false |
79 | t.string :amount_fraction, :null => false |
80 | t.float :amount_for_sorting |
81 | |
82 | t.timestamps |
83 | end |
84 | |
85 | add_index :donations, :user_id |
86 | add_index :donations, :poll_id |
87 | add_index :donations, :currency_id |
88 | |
89 | end |
90 | |
91 | def self.down |
92 | drop_table :donations |
93 | end |
94 | end |