-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
69 lines (61 loc) · 2.95 KB
/
models.py
File metadata and controls
69 lines (61 loc) · 2.95 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
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
from sqlalchemy import Column, BigInteger, Integer, Text, Date, Numeric, JSON, Enum, ForeignKey, TIMESTAMP
from sqlalchemy.orm import relationship
from .db import Base
import enum
class InstrumentKind(enum.Enum):
equity='equity'; note='note'; safe='safe'; loan='loan'; other='other'
class EventType(enum.Enum):
investment='investment'; distribution='distribution'; repayment='repayment'; conversion='conversion'; info='info'
class Company(Base):
__tablename__='companies'
company_pk = Column(BigInteger, primary_key=True, autoincrement=True)
company_id = Column(Text, unique=True, nullable=False)
legal_name = Column(Text, nullable=False)
description = Column(Text)
created_at = Column(TIMESTAMP)
aliases = relationship("CompanyAlias", back_populates="company")
instruments = relationship("Instrument", back_populates="company")
events = relationship("Event", back_populates="company")
updates = relationship("Update", back_populates="company")
class CompanyAlias(Base):
__tablename__='company_aliases'
company_pk = Column(BigInteger, ForeignKey('companies.company_pk', ondelete='CASCADE'), primary_key=True)
alias = Column(Text, primary_key=True)
company = relationship("Company", back_populates="aliases")
class Instrument(Base):
__tablename__='instruments'
instrument_id = Column(BigInteger, primary_key=True, autoincrement=True)
company_pk = Column(BigInteger, ForeignKey('companies.company_pk', ondelete='CASCADE'))
kind = Column(Enum(InstrumentKind), nullable=False)
name = Column(Text)
terms_json = Column(JSON)
company = relationship("Company", back_populates="instruments")
events = relationship("Event", back_populates="instrument")
class Event(Base):
__tablename__='events'
event_id = Column(BigInteger, primary_key=True, autoincrement=True)
company_pk = Column(BigInteger, ForeignKey('companies.company_pk', ondelete='CASCADE'))
instrument_id = Column(BigInteger, ForeignKey('instruments.instrument_id'))
event_date = Column(Date, nullable=False)
type = Column(Enum(EventType), nullable=False)
amount = Column(Numeric(15,2))
subtype = Column(Text)
note = Column(Text)
party_in = Column(Text)
party_out = Column(Text)
created_at = Column(TIMESTAMP)
company = relationship("Company", back_populates="events")
instrument = relationship("Instrument", back_populates="events")
class Update(Base):
__tablename__='updates'
update_id = Column(Text, primary_key=True) # use UUID string
company_pk = Column(BigInteger, ForeignKey('companies.company_pk', ondelete='CASCADE'))
date = Column(Date, nullable=False)
source_type = Column(Text, nullable=False)
source_ref = Column(Text)
update_type = Column(Text, nullable=False)
headline = Column(Text, nullable=False)
body_text = Column(Text)
structured_data = Column(JSON)
created_at = Column(TIMESTAMP)
company = relationship("Company", back_populates="updates")