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