-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmodels.py
More file actions
42 lines (33 loc) · 1.1 KB
/
models.py
File metadata and controls
42 lines (33 loc) · 1.1 KB
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
import datetime
import os
from sqlalchemy import Column, String, DateTime, Float, Integer
from sqlalchemy.engine import URL
from sqlalchemy.orm import declarative_base
DATABASE_URL = URL.create(
host=os.environ.get('POSTGRES_HOST', 'localhost'),
port=os.environ.get('POSTGRES_PORT', 5432),
username=os.environ.get('POSTGRES_USER', 'postgres'),
password=os.environ.get('POSTGRES_PASSWORD', 'password'),
database=os.environ.get('POSTGRES_DB', 'test_timescaledb'),
drivername=os.environ.get('DRIVERNAME', 'timescaledb')
)
Base = declarative_base()
class Metric(Base):
__tablename__ = 'metrics'
__table_args__ = (
{
'timescaledb_hypertable': {
'time_column_name': 'timestamp'
}
}
)
id = Column(Integer, primary_key=True , autoincrement=True)
name = Column(String)
value = Column(Float)
timestamp = Column(
DateTime(), default=datetime.datetime.now, primary_key=True
)
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String)