|
1 | 1 | import pymongo
|
2 | 2 |
|
3 |
| -from opensensor.utils import get_open_sensor_db |
| 3 | +from opensensor.db import get_open_sensor_db |
4 | 4 |
|
5 | 5 | # Script for creating the Time Series
|
6 | 6 |
|
7 | 7 | db = get_open_sensor_db()
|
8 |
| -try: |
9 |
| - db.create_collection( |
10 |
| - "Temperature", |
11 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
12 |
| - ) |
13 |
| -except pymongo.errors.CollectionInvalid: |
14 |
| - print("Temperature collection Already exists, skipping ...") |
15 |
| - |
16 |
| -try: |
17 |
| - db.create_collection( |
18 |
| - "Humidity", |
19 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
20 |
| - ) |
21 |
| -except pymongo.errors.CollectionInvalid: |
22 |
| - print("Humidity collection Already exists, skipping ...") |
23 |
| - |
24 |
| -try: |
25 |
| - db.create_collection( |
26 |
| - "Pressure", |
27 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
28 |
| - ) |
29 |
| -except pymongo.errors.CollectionInvalid: |
30 |
| - print("Pressure collection Already exists, skipping ...") |
| 8 | +# try: |
| 9 | +# db.create_collection( |
| 10 | +# "Temperature", |
| 11 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 12 | +# ) |
| 13 | +# except pymongo.errors.CollectionInvalid: |
| 14 | +# print("Temperature collection Already exists, skipping ...") |
| 15 | +# |
| 16 | +# try: |
| 17 | +# db.create_collection( |
| 18 | +# "Humidity", |
| 19 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 20 | +# ) |
| 21 | +# except pymongo.errors.CollectionInvalid: |
| 22 | +# print("Humidity collection Already exists, skipping ...") |
| 23 | +# |
| 24 | +# try: |
| 25 | +# db.create_collection( |
| 26 | +# "Pressure", |
| 27 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 28 | +# ) |
| 29 | +# except pymongo.errors.CollectionInvalid: |
| 30 | +# print("Pressure collection Already exists, skipping ...") |
| 31 | +# |
| 32 | +# try: |
| 33 | +# db.create_collection( |
| 34 | +# "Lux", |
| 35 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 36 | +# ) |
| 37 | +# except pymongo.errors.CollectionInvalid: |
| 38 | +# print("Lux collection Already exists, skipping ...") |
| 39 | +# |
| 40 | +# try: |
| 41 | +# db.create_collection( |
| 42 | +# "CO2", |
| 43 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 44 | +# ) |
| 45 | +# except pymongo.errors.CollectionInvalid: |
| 46 | +# print("CO2 collection Already exists, skipping ...") |
| 47 | +# |
| 48 | +# try: |
| 49 | +# db.create_collection( |
| 50 | +# "Moisture", |
| 51 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 52 | +# ) |
| 53 | +# except pymongo.errors.CollectionInvalid: |
| 54 | +# print("Moisture collection Already exists, skipping ...") |
| 55 | +# |
| 56 | +# try: |
| 57 | +# db.create_collection( |
| 58 | +# "pH", |
| 59 | +# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 60 | +# ) |
| 61 | +# except pymongo.errors.CollectionInvalid: |
| 62 | +# print("pH collection Already exists, skipping ...") |
31 | 63 |
|
32 | 64 | try:
|
33 | 65 | db.create_collection(
|
34 |
| - "Lux", |
| 66 | + "FreeTier", |
35 | 67 | timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"},
|
| 68 | + # expireAfterSeconds=8000000, |
36 | 69 | )
|
37 | 70 | except pymongo.errors.CollectionInvalid:
|
38 |
| - print("Lux collection Already exists, skipping ...") |
| 71 | + print("FreeTier collection Already exists, skipping ...") |
39 | 72 |
|
40 |
| -try: |
41 |
| - db.create_collection( |
42 |
| - "CO2", |
43 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
44 |
| - ) |
45 |
| -except pymongo.errors.CollectionInvalid: |
46 |
| - print("CO2 collection Already exists, skipping ...") |
47 | 73 |
|
48 | 74 | try:
|
49 | 75 | db.create_collection(
|
50 |
| - "Moisture", |
51 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 76 | + "Migration", |
| 77 | + # timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 78 | + # expireAfterSeconds=8000000, |
52 | 79 | )
|
53 |
| -except pymongo.errors.CollectionInvalid: |
54 |
| - print("Moisture collection Already exists, skipping ...") |
| 80 | + db.Migration.create_index([("migration_name", 1)], unique=True) |
55 | 81 |
|
56 |
| -try: |
57 |
| - db.create_collection( |
58 |
| - "pH", |
59 |
| - timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
60 |
| - ) |
61 | 82 | except pymongo.errors.CollectionInvalid:
|
62 |
| - print("pH collection Already exists, skipping ...") |
| 83 | + print("Migration collection Already exists, skipping ...") |
0 commit comments