MesskitSetup » History » Version 1
Lance Edgar, 03/06/2022 10:01 PM
Initial version; hopefully everything needed to query CORE DB
1 | 1 | Lance Edgar | {{>toc}} |
---|---|---|---|
2 | |||
3 | # CORE-POS Integration Setup for Messkit |
||
4 | |||
5 | At this time the setup is manual; see below for steps. |
||
6 | |||
7 | ## Install Packages |
||
8 | |||
9 | There are a few packages required but you only need to specify one, the rest are brought in as dependencies. Make sure your virtual environment is activated and then install: |
||
10 | |||
11 | ```sh |
||
12 | source /path/to/envs/messkit/bin/activate |
||
13 | pip install tailbone-corepos |
||
14 | ``` |
||
15 | |||
16 | ## Configure Messkit |
||
17 | |||
18 | Now you'll add the database connection(s) to `/path/to/envs/messkit/app/rattail.conf` - examples follow but first to clarify: |
||
19 | |||
20 | CORE has (at least!) 5 different types of databases: 3 for Office, 2 for Lane. Rattail splits these up at a logical level, meaning each of the 5 types must be configured separately. In practice you normally only need to use 1 or 2 of these types: |
||
21 | |||
22 | - `office_op` |
||
23 | - `office_trans` |
||
24 | - `office_trans_archive` |
||
25 | - `lane_op` |
||
26 | - `lane_trans` |
||
27 | |||
28 | Also, you must give these connections an explicit timeout, after which they will be "refreshed" when in use. This to work around MySQL behavior which will "expire" a connection if has not been used for a while. IIRC it will expire after like 8 hours? But we set our timeout to 1 hour (3600 seconds) to be safe. You must do this for *each* connection. (It technically should only matter for "long-running" processes..of which the web app would be one, if you have it talking to the CORE DB..datasync would be another.) |
||
29 | |||
30 | If you just want to query the CORE Office "operational" DB: |
||
31 | |||
32 | ```ini |
||
33 | [corepos.db.office_op] |
||
34 | default.url = mysql+mysqlconnector://USERNAME:PASSWORD@pos-server/core_op |
||
35 | default.pool_recycle = 3600 |
||
36 | ``` |
||
37 | |||
38 | But you can specify as many as you want. (Note, these are all "Office Op" type!) There ideally should be a "default" connection though: |
||
39 | |||
40 | ```ini |
||
41 | [corepos.db.office_op] |
||
42 | keys = default, store2, store3 |
||
43 | default.url = mysql+mysqlconnector://USERNAME:PASSWORD@store1-server/core_op |
||
44 | default.pool_recycle = 3600 |
||
45 | store2.url = mysql+mysqlconnector://USERNAME:PASSWORD@store2-server/core_op |
||
46 | store2.pool_recycle = 3600 |
||
47 | store3.url = mysql+mysqlconnector://USERNAME:PASSWORD@store3-server/core_op |
||
48 | store3.pool_recycle = 3600 |
||
49 | ``` |
||
50 | |||
51 | And if you want to query the other types too, here is a "complete" setup for 1 server and 2 lanes: |
||
52 | |||
53 | ```ini |
||
54 | [corepos.db.office_op] |
||
55 | default.url = mysql+mysqlconnector://USERNAME:PASSWORD@pos-server/core_op |
||
56 | default.pool_recycle = 3600 |
||
57 | |||
58 | [corepos.db.office_trans] |
||
59 | default.url = mysql+mysqlconnector://USERNAME:PASSWORD@pos-server/core_trans |
||
60 | default.pool_recycle = 3600 |
||
61 | |||
62 | [corepos.db.office_trans_archive] |
||
63 | default.url = mysql+mysqlconnector://USERNAME:PASSWORD@pos-server/trans_archive |
||
64 | default.pool_recycle = 3600 |
||
65 | |||
66 | # nb. no default here, but that is okay as long as no code requires one! |
||
67 | [corepos.db.lane_op] |
||
68 | keys = lane1, lane2 |
||
69 | lane1.url = mysql+mysqlconnector://USERNAME:PASSWORD@lane1/opdata |
||
70 | lane1.pool_recycle = 3600 |
||
71 | lane2.url = mysql+mysqlconnector://USERNAME:PASSWORD@lane2/opdata |
||
72 | lane2.pool_recycle = 3600 |
||
73 | |||
74 | [corepos.db.lane_trans] |
||
75 | keys = lane1, lane2 |
||
76 | lane1.url = mysql+mysqlconnector://USERNAME:PASSWORD@lane1/translog |
||
77 | lane1.pool_recycle = 3600 |
||
78 | lane2.url = mysql+mysqlconnector://USERNAME:PASSWORD@lane2/translog |
||
79 | lane2.pool_recycle = 3600 |
||
80 | ``` |
||
81 | |||
82 | You also should modify your `/path/to/envs/messkit/app/upgrade.sh` script so that the integration packages are updated whenever your app is. |
||
83 | |||
84 | In that script you should see this line: |
||
85 | |||
86 | ```sh |
||
87 | $PIP install $QUIET --upgrade --upgrade-strategy eager Messkit |
||
88 | ``` |
||
89 | |||
90 | You should modify that to look like this: |
||
91 | |||
92 | ```sh |
||
93 | $PIP install $QUIET --upgrade --upgrade-strategy eager Messkit tailbone-corepos |
||
94 | ``` |
||
95 | |||
96 | |||
97 | ### Test Connectivity |
||
98 | |||
99 | With the above in place you can test connectivity with a simple Python script - create the file at `/path/to/envs/messkit/app/test-core-cxn.py` and in it put: |
||
100 | |||
101 | ```python |
||
102 | from rattail.config import make_config |
||
103 | config = make_config('app/quiet.conf', versioning=False) |
||
104 | |||
105 | from corepos.db.office_op import Session as CoreSession, model as corepos |
||
106 | core_session = CoreSession() # nb. uses 'default' engine |
||
107 | for store in core_session.query(corepos.Store).order_by('storeID'): |
||
108 | print(store) |
||
109 | core_session.close() |
||
110 | ``` |
||
111 | |||
112 | Then run it like so: |
||
113 | |||
114 | ```sh |
||
115 | cd /path/to/envs/messkit |
||
116 | bin/python app/test-core-cxn.py |
||
117 | ``` |
||
118 | |||
119 | If you want to test connectivity for *all* your Office Op DBs then the script could be like (run it the same way): |
||
120 | |||
121 | ```python |
||
122 | from rattail.config import make_config |
||
123 | config = make_config('app/quiet.conf', versioning=False) |
||
124 | |||
125 | from corepos.db.office_op import Session as CoreSession, model as corepos |
||
126 | for key, engine in config.core_office_op_engines.items(): |
||
127 | print("{} says:".format(key)) |
||
128 | core_session = CoreSession(bind=engine) |
||
129 | for store in core_session.query(corepos.Store).order_by('storeID'): |
||
130 | print("\t{}".format(store)) |
||
131 | core_session.close() |
||
132 | ``` |
||
133 | |||
134 | ### Include CORE Views |
||
135 | |||
136 | Now that you can talk to the CORE DB, that means Messkit can show you that data directly in the web app. To see it you must "include" whichever views you want. For more information see [Configurable Views](https://rattailproject.org/docs/messkit/features.html#configurable-views). |
||
137 | |||
138 | However please note that the integration comes with two different types of views. The ones you want at this point are views which show the CORE tables (listed under the "corepos" section when configuring). |
||
139 | |||
140 | The other type of views it has are customizations of the native "rattail" views. But you can't use those until you extend the DB schema, next section. |
||
141 | |||
142 | ### Extend DB Schema |
||
143 | |||
144 | If you want to *import* data from CORE into Messkit then you will need to extend its schema. If you only need to *query* the CORE data but not import to Messkit, you can skip this section. |
||
145 | |||
146 | One of the packages that got installed (namely, [rattail-corepos](https://redmine.rattailproject.org/projects/corepos-integration/repository/rattail-corepos)) contains the DB extensions and you now must configure Messkit to use them. |
||
147 | |||
148 | Edit the file at `/path/to/envs/messkit/app/rattail.conf` and locate its `[alembic]` section. It should look like this currently: |
||
149 | |||
150 | ```ini |
||
151 | [alembic] |
||
152 | script_location = rattail.db:alembic |
||
153 | version_locations = rattail.db:alembic/versions |
||
154 | ``` |
||
155 | |||
156 | But you should update that last line so it looks like this: |
||
157 | |||
158 | ```ini |
||
159 | [alembic] |
||
160 | script_location = rattail.db:alembic |
||
161 | version_locations = rattail_corepos.db:alembic/versions rattail.db:alembic/versions |
||
162 | ``` |
||
163 | |||
164 | Then run the migration tool to apply changes to your Messkit DB: |
||
165 | |||
166 | ```sh |
||
167 | cd /path/to/envs/messkit |
||
168 | bin/alembic -c app/rattail.conf upgrade heads |
||
169 | ``` |
||
170 | |||
171 | So the DB tables exist now, but Messkit also needs to know those tables should be considered part of the app so to speak. Edit `/path/to/envs/messkit/app/poser/poser/db/model/__init__.py` and add the line: |
||
172 | |||
173 | ```python |
||
174 | from rattail_corepos.db.model import * |
||
175 | ``` |
||
176 | |||
177 | That's all for setup, now you can test the import. This command only imports the Department (`departments`) table from CORE (the "default" DB of "office_op" type), into corresponding Messkit table. But it uses the `--dry-run` flag which means the DB transaction is rolled back. Omit that flag if you really want the data in Messkit. |
||
178 | |||
179 | ```sh |
||
180 | cd /path/to/envs/messkit |
||
181 | bin/rattail -c app/quiet.conf import-corepos-db Department --progress --dry-run |
||
182 | ``` |
||
183 | |||
184 | You now can enable/include the customized "rattail" views provided by `tailbone_corepos` if you like. |