mc-postgres-db 0.1.0__py3-none-any.whl → 1.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mc_postgres_db-0.1.0.dist-info → mc_postgres_db-1.0.7.dist-info}/METADATA +2 -2
- mc_postgres_db-1.0.7.dist-info/RECORD +5 -0
- mc_postgres_db-1.0.7.dist-info/top_level.txt +1 -0
- mcpdb/tables.py +257 -0
- alembic/env.py +0 -83
- alembic/versions/4056c087960a_.py +0 -149
- alembic/versions/8b53c8e91507_adding_new_market_table_and_content_.py +0 -114
- mc_postgres_db-0.1.0.dist-info/RECORD +0 -7
- mc_postgres_db-0.1.0.dist-info/top_level.txt +0 -1
- {mc_postgres_db-0.1.0.dist-info → mc_postgres_db-1.0.7.dist-info}/WHEEL +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mc-postgres-db
|
3
|
-
Version:
|
3
|
+
Version: 1.0.7
|
4
4
|
Summary: Add your description here
|
5
5
|
Requires-Python: >=3.12
|
6
6
|
Description-Content-Type: text/markdown
|
7
7
|
Requires-Dist: alembic>=1.16.2
|
8
|
-
Requires-Dist: psycopg2>=2.9.10
|
8
|
+
Requires-Dist: psycopg2-binary>=2.9.10
|
9
9
|
Requires-Dist: ruff>=0.12.0
|
10
10
|
Requires-Dist: sqlalchemy>=2.0.41
|
@@ -0,0 +1,5 @@
|
|
1
|
+
mcpdb/tables.py,sha256=jeyQH3u7DvOxLpIM6u5AaSLrBaL5UxvXTFK29ytJ_A8,10201
|
2
|
+
mc_postgres_db-1.0.7.dist-info/METADATA,sha256=Lwnx5ZHsUvxPpJRGVqH8JQBijeEtQFUHPmEwCj3bIfE,289
|
3
|
+
mc_postgres_db-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
4
|
+
mc_postgres_db-1.0.7.dist-info/top_level.txt,sha256=xiCw1E_-H0o0I8j5PbuWddHW1iwrGwntb2enCqa4FQA,6
|
5
|
+
mc_postgres_db-1.0.7.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
mcpdb
|
mcpdb/tables.py
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
import datetime
|
2
|
+
from typing import Optional
|
3
|
+
|
4
|
+
from sqlalchemy import Engine, ForeignKey, String, func, select
|
5
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
|
6
|
+
|
7
|
+
|
8
|
+
class Base(DeclarativeBase):
|
9
|
+
"""
|
10
|
+
Base class for SQLAlchemy models.
|
11
|
+
This class is used to define the base for all models in the application.
|
12
|
+
It inherits from DeclarativeBase, which is a SQLAlchemy class that provides
|
13
|
+
a declarative interface for defining models.
|
14
|
+
"""
|
15
|
+
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
19
|
+
class AssetType(Base):
|
20
|
+
__tablename__ = "asset_type"
|
21
|
+
|
22
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
23
|
+
name: Mapped[str] = mapped_column(String(30), nullable=False)
|
24
|
+
description: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
25
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
26
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
27
|
+
nullable=False, server_default=func.now()
|
28
|
+
)
|
29
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
30
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
31
|
+
)
|
32
|
+
|
33
|
+
def __repr__(self):
|
34
|
+
return f"{AssetType.__name__}({self.id}, {self.name})"
|
35
|
+
|
36
|
+
|
37
|
+
class Asset(Base):
|
38
|
+
__tablename__ = "asset"
|
39
|
+
|
40
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
41
|
+
asset_type_id: Mapped[int] = mapped_column(
|
42
|
+
ForeignKey("asset_type.id"), nullable=False
|
43
|
+
)
|
44
|
+
name: Mapped[str] = mapped_column(String(30), nullable=False)
|
45
|
+
description: Mapped[Optional[str]]
|
46
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
47
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
48
|
+
nullable=False, server_default=func.now()
|
49
|
+
)
|
50
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
51
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
52
|
+
)
|
53
|
+
|
54
|
+
def __repr__(self):
|
55
|
+
return f"{Asset.__name__}({self.id}, {self.name})"
|
56
|
+
|
57
|
+
|
58
|
+
class ProviderType(Base):
|
59
|
+
__tablename__ = "provider_type"
|
60
|
+
|
61
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
62
|
+
name: Mapped[str] = mapped_column(String(30), nullable=False)
|
63
|
+
description: Mapped[Optional[str]] = mapped_column(String(1000), nullable=True)
|
64
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
65
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
66
|
+
nullable=False, server_default=func.now()
|
67
|
+
)
|
68
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
69
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
70
|
+
)
|
71
|
+
|
72
|
+
def __repr__(self):
|
73
|
+
return f"{ProviderType.__name__}({self.id}, {self.name})"
|
74
|
+
|
75
|
+
|
76
|
+
class Provider(Base):
|
77
|
+
__tablename__ = "provider"
|
78
|
+
|
79
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
80
|
+
provider_type_id: Mapped[int] = mapped_column(
|
81
|
+
ForeignKey("provider_type.id"), nullable=False
|
82
|
+
)
|
83
|
+
name: Mapped[str] = mapped_column(String(30), nullable=False)
|
84
|
+
description: Mapped[Optional[str]] = mapped_column(String(1000), nullable=True)
|
85
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
86
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
87
|
+
nullable=False, server_default=func.now()
|
88
|
+
)
|
89
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
90
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
91
|
+
)
|
92
|
+
|
93
|
+
def __repr__(self):
|
94
|
+
return f"{Provider.__name__}({self.id}, {self.name})"
|
95
|
+
|
96
|
+
def get_all_assets(
|
97
|
+
self,
|
98
|
+
engine: Engine,
|
99
|
+
asset_ids: list[int] = [],
|
100
|
+
) -> set["ProviderAsset"]:
|
101
|
+
with Session(engine) as session:
|
102
|
+
# Subquery to get the latest date for each provider_id, asset_id combination
|
103
|
+
latest_dates_subq = (
|
104
|
+
select(
|
105
|
+
ProviderAsset.provider_id,
|
106
|
+
ProviderAsset.asset_id,
|
107
|
+
func.max(ProviderAsset.date).label("max_date"),
|
108
|
+
)
|
109
|
+
.where(ProviderAsset.provider_id == self.id, ProviderAsset.is_active)
|
110
|
+
.group_by(ProviderAsset.provider_id, ProviderAsset.asset_id)
|
111
|
+
.subquery()
|
112
|
+
)
|
113
|
+
|
114
|
+
# Query to get assets that have provider_asset entries with the latest dates
|
115
|
+
query = (
|
116
|
+
select(ProviderAsset)
|
117
|
+
.join(Asset, ProviderAsset.asset_id == Asset.id)
|
118
|
+
.join(
|
119
|
+
latest_dates_subq,
|
120
|
+
(ProviderAsset.provider_id == latest_dates_subq.c.provider_id)
|
121
|
+
& (ProviderAsset.asset_id == latest_dates_subq.c.asset_id)
|
122
|
+
& (ProviderAsset.date == latest_dates_subq.c.max_date),
|
123
|
+
)
|
124
|
+
.where(
|
125
|
+
ProviderAsset.provider_id == self.id,
|
126
|
+
ProviderAsset.is_active,
|
127
|
+
Asset.is_active,
|
128
|
+
)
|
129
|
+
)
|
130
|
+
|
131
|
+
# Add asset ID filter if provided
|
132
|
+
if asset_ids:
|
133
|
+
query = query.where(ProviderAsset.asset_id.in_(asset_ids))
|
134
|
+
|
135
|
+
# Execute query and return results as a set
|
136
|
+
assets = session.scalars(query).all()
|
137
|
+
return set(assets)
|
138
|
+
|
139
|
+
|
140
|
+
class ProviderAsset(Base):
|
141
|
+
__tablename__ = "provider_asset"
|
142
|
+
|
143
|
+
date: Mapped[datetime.date] = mapped_column(primary_key=True)
|
144
|
+
provider_id: Mapped[int] = mapped_column(
|
145
|
+
ForeignKey("provider.id"), nullable=False, primary_key=True
|
146
|
+
)
|
147
|
+
asset_id: Mapped[int] = mapped_column(
|
148
|
+
ForeignKey("asset.id"), nullable=False, primary_key=True
|
149
|
+
)
|
150
|
+
asset_code: Mapped[str] = mapped_column(String(30), nullable=False)
|
151
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
152
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
153
|
+
nullable=False, server_default=func.now()
|
154
|
+
)
|
155
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
156
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
157
|
+
)
|
158
|
+
|
159
|
+
def __repr__(self):
|
160
|
+
return f"{ProviderAsset.__name__}({self.date}, {self.provider_id}, {self.asset_id})"
|
161
|
+
|
162
|
+
|
163
|
+
class ProviderAssetOrder(Base):
|
164
|
+
__tablename__ = "provider_asset_order"
|
165
|
+
|
166
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
167
|
+
timestamp: Mapped[datetime.datetime] = mapped_column(nullable=False)
|
168
|
+
provider_id: Mapped[int] = mapped_column(ForeignKey("provider.id"), nullable=False)
|
169
|
+
from_asset_id: Mapped[int] = mapped_column(ForeignKey("asset.id"), nullable=False)
|
170
|
+
to_asset_id: Mapped[int] = mapped_column(ForeignKey("asset.id"), nullable=False)
|
171
|
+
price: Mapped[float] = mapped_column(nullable=True)
|
172
|
+
volume: Mapped[float] = mapped_column(nullable=True)
|
173
|
+
|
174
|
+
def __repr__(self):
|
175
|
+
return f"{ProviderAssetOrder.__name__}(id={self.id}, timestamp={self.timestamp}, provider_id={self.provider_id}, from_asset_id={self.from_asset_id}, to_asset_id={self.to_asset_id}, price={self.price}, volume={self.volume})"
|
176
|
+
|
177
|
+
|
178
|
+
class ProviderAssetMarket(Base):
|
179
|
+
__tablename__ = "provider_asset_market"
|
180
|
+
|
181
|
+
timestamp: Mapped[datetime.datetime] = mapped_column(
|
182
|
+
nullable=False, primary_key=True
|
183
|
+
)
|
184
|
+
provider_id: Mapped[int] = mapped_column(
|
185
|
+
ForeignKey("provider.id"), nullable=False, primary_key=True
|
186
|
+
)
|
187
|
+
asset_id: Mapped[int] = mapped_column(
|
188
|
+
ForeignKey("asset.id"), nullable=False, primary_key=True
|
189
|
+
)
|
190
|
+
close: Mapped[float] = mapped_column(nullable=True, comment="Closing price")
|
191
|
+
open: Mapped[float] = mapped_column(nullable=True, comment="Opening price")
|
192
|
+
high: Mapped[float] = mapped_column(nullable=True, comment="Highest price")
|
193
|
+
low: Mapped[float] = mapped_column(nullable=True, comment="Lowest price")
|
194
|
+
volume: Mapped[float] = mapped_column(nullable=True, comment="Volume traded")
|
195
|
+
best_bid: Mapped[float] = mapped_column(nullable=True, comment="Best bid price")
|
196
|
+
best_ask: Mapped[float] = mapped_column(nullable=True, comment="Best ask price")
|
197
|
+
|
198
|
+
def __repr__(self):
|
199
|
+
return f"{ProviderAssetMarket.__name__}(id={self.id}, provider_id={self.provider_id}, asset_id={self.asset_id}, market_type={self.market_type})"
|
200
|
+
|
201
|
+
|
202
|
+
class ContentType(Base):
|
203
|
+
__tablename__ = "content_type"
|
204
|
+
|
205
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
206
|
+
name: Mapped[str] = mapped_column(String(30), nullable=False)
|
207
|
+
description: Mapped[Optional[str]] = mapped_column(String(1000), nullable=True)
|
208
|
+
is_active: Mapped[bool] = mapped_column(default=True)
|
209
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
210
|
+
nullable=False, server_default=func.now()
|
211
|
+
)
|
212
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
213
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
214
|
+
)
|
215
|
+
|
216
|
+
def __repr__(self):
|
217
|
+
return f"{ContentType.__name__}({self.id}, {self.name})"
|
218
|
+
|
219
|
+
|
220
|
+
class ProviderContent(Base):
|
221
|
+
__tablename__ = "provider_content"
|
222
|
+
|
223
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
224
|
+
timestamp: Mapped[datetime.datetime] = mapped_column(nullable=False)
|
225
|
+
provider_id: Mapped[int] = mapped_column(ForeignKey("provider.id"), nullable=False)
|
226
|
+
provider_unique_identifier: Mapped[str] = mapped_column(
|
227
|
+
String(1000), nullable=False
|
228
|
+
)
|
229
|
+
content_type_id: Mapped[int] = mapped_column(
|
230
|
+
ForeignKey("content_type.id"), nullable=False
|
231
|
+
)
|
232
|
+
author: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
233
|
+
title: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
|
234
|
+
content: Mapped[str] = mapped_column(String(), nullable=False)
|
235
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
236
|
+
nullable=False, server_default=func.now()
|
237
|
+
)
|
238
|
+
updated_at: Mapped[Optional[datetime.datetime]] = mapped_column(
|
239
|
+
nullable=False, server_onupdate=func.now(), server_default=func.now()
|
240
|
+
)
|
241
|
+
|
242
|
+
def __repr__(self):
|
243
|
+
return f"{ProviderContent.__name__}(id={self.id}, provider_id={self.provider_id}, content_type={self.content_type})"
|
244
|
+
|
245
|
+
|
246
|
+
class AssetContent(Base):
|
247
|
+
__tablename__ = "asset_content"
|
248
|
+
|
249
|
+
content_id: Mapped[int] = mapped_column(
|
250
|
+
ForeignKey("provider_content.id"), primary_key=True, nullable=False
|
251
|
+
)
|
252
|
+
asset_id: Mapped[int] = mapped_column(
|
253
|
+
ForeignKey("asset.id"), primary_key=True, nullable=False
|
254
|
+
)
|
255
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
256
|
+
nullable=False, server_default=func.now()
|
257
|
+
)
|
alembic/env.py
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from logging.config import fileConfig
|
3
|
-
|
4
|
-
from sqlalchemy import engine_from_config
|
5
|
-
from sqlalchemy import pool
|
6
|
-
|
7
|
-
|
8
|
-
from alembic import context
|
9
|
-
from tables import Base # Import your SQLAlchemy Base class
|
10
|
-
from dotenv import load_dotenv
|
11
|
-
|
12
|
-
load_dotenv() # Load environment variables from .env file
|
13
|
-
|
14
|
-
# this is the Alembic Config object, which provides
|
15
|
-
# access to the values within the .ini file in use.
|
16
|
-
config = context.config
|
17
|
-
|
18
|
-
# Interpret the config file for Python logging.
|
19
|
-
# This line sets up loggers basically.
|
20
|
-
if config.config_file_name is not None:
|
21
|
-
fileConfig(config.config_file_name)
|
22
|
-
|
23
|
-
# add your model's MetaData object here
|
24
|
-
# for 'autogenerate' support
|
25
|
-
# from myapp import mymodel
|
26
|
-
# target_metadata = mymodel.Base.metadata
|
27
|
-
target_metadata = Base.metadata # Use the metadata from your Base class
|
28
|
-
|
29
|
-
# other values from the config, defined by the needs of env.py,
|
30
|
-
# can be acquired:
|
31
|
-
# my_important_option = config.get_main_option("my_important_option")
|
32
|
-
url = os.environ["SQLALCHEMY_DATABASE_URL"]
|
33
|
-
config.set_main_option("sqlalchemy.url", url)
|
34
|
-
|
35
|
-
|
36
|
-
def run_migrations_offline() -> None:
|
37
|
-
"""Run migrations in 'offline' mode.
|
38
|
-
|
39
|
-
This configures the context with just a URL
|
40
|
-
and not an Engine, though an Engine is acceptable
|
41
|
-
here as well. By skipping the Engine creation
|
42
|
-
we don't even need a DBAPI to be available.
|
43
|
-
|
44
|
-
Calls to context.execute() here emit the given string to the
|
45
|
-
script output.
|
46
|
-
|
47
|
-
"""
|
48
|
-
url = config.get_main_option("sqlalchemy.url")
|
49
|
-
context.configure(
|
50
|
-
url=url,
|
51
|
-
target_metadata=target_metadata,
|
52
|
-
literal_binds=True,
|
53
|
-
dialect_opts={"paramstyle": "named"},
|
54
|
-
)
|
55
|
-
|
56
|
-
with context.begin_transaction():
|
57
|
-
context.run_migrations()
|
58
|
-
|
59
|
-
|
60
|
-
def run_migrations_online() -> None:
|
61
|
-
"""Run migrations in 'online' mode.
|
62
|
-
|
63
|
-
In this scenario we need to create an Engine
|
64
|
-
and associate a connection with the context.
|
65
|
-
|
66
|
-
"""
|
67
|
-
connectable = engine_from_config(
|
68
|
-
config.get_section(config.config_ini_section, {}),
|
69
|
-
prefix="sqlalchemy.",
|
70
|
-
poolclass=pool.NullPool,
|
71
|
-
)
|
72
|
-
|
73
|
-
with connectable.connect() as connection:
|
74
|
-
context.configure(connection=connection, target_metadata=target_metadata)
|
75
|
-
|
76
|
-
with context.begin_transaction():
|
77
|
-
context.run_migrations()
|
78
|
-
|
79
|
-
|
80
|
-
if context.is_offline_mode():
|
81
|
-
run_migrations_offline()
|
82
|
-
else:
|
83
|
-
run_migrations_online()
|
@@ -1,149 +0,0 @@
|
|
1
|
-
"""empty message
|
2
|
-
|
3
|
-
Revision ID: 4056c087960a
|
4
|
-
Revises:
|
5
|
-
Create Date: 2025-06-23 18:38:27.569904
|
6
|
-
|
7
|
-
"""
|
8
|
-
|
9
|
-
from typing import Sequence, Union
|
10
|
-
|
11
|
-
from alembic import op
|
12
|
-
import sqlalchemy as sa
|
13
|
-
|
14
|
-
|
15
|
-
# revision identifiers, used by Alembic.
|
16
|
-
revision: str = "4056c087960a"
|
17
|
-
down_revision: Union[str, Sequence[str], None] = None
|
18
|
-
branch_labels: Union[str, Sequence[str], None] = None
|
19
|
-
depends_on: Union[str, Sequence[str], None] = None
|
20
|
-
|
21
|
-
|
22
|
-
def upgrade() -> None:
|
23
|
-
"""Upgrade schema."""
|
24
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
25
|
-
op.create_table(
|
26
|
-
"asset_type",
|
27
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
28
|
-
sa.Column("name", sa.String(length=30), nullable=False),
|
29
|
-
sa.Column("description", sa.String(length=100), nullable=True),
|
30
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
31
|
-
sa.Column(
|
32
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
33
|
-
),
|
34
|
-
sa.Column(
|
35
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
36
|
-
),
|
37
|
-
sa.PrimaryKeyConstraint("id"),
|
38
|
-
)
|
39
|
-
op.create_table(
|
40
|
-
"provider_type",
|
41
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
42
|
-
sa.Column("name", sa.String(length=30), nullable=False),
|
43
|
-
sa.Column("description", sa.String(length=1000), nullable=True),
|
44
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
45
|
-
sa.Column(
|
46
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
47
|
-
),
|
48
|
-
sa.Column(
|
49
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
50
|
-
),
|
51
|
-
sa.PrimaryKeyConstraint("id"),
|
52
|
-
)
|
53
|
-
op.create_table(
|
54
|
-
"asset",
|
55
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
56
|
-
sa.Column("asset_type_id", sa.Integer(), nullable=False),
|
57
|
-
sa.Column("name", sa.String(length=30), nullable=False),
|
58
|
-
sa.Column("description", sa.String(), nullable=True),
|
59
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
60
|
-
sa.Column(
|
61
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
62
|
-
),
|
63
|
-
sa.Column(
|
64
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
65
|
-
),
|
66
|
-
sa.ForeignKeyConstraint(
|
67
|
-
["asset_type_id"],
|
68
|
-
["asset_type.id"],
|
69
|
-
),
|
70
|
-
sa.PrimaryKeyConstraint("id"),
|
71
|
-
)
|
72
|
-
op.create_table(
|
73
|
-
"provider",
|
74
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
75
|
-
sa.Column("provider_type_id", sa.Integer(), nullable=False),
|
76
|
-
sa.Column("name", sa.String(length=30), nullable=False),
|
77
|
-
sa.Column("description", sa.String(length=1000), nullable=True),
|
78
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
79
|
-
sa.Column(
|
80
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
81
|
-
),
|
82
|
-
sa.Column(
|
83
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
84
|
-
),
|
85
|
-
sa.ForeignKeyConstraint(
|
86
|
-
["provider_type_id"],
|
87
|
-
["provider_type.id"],
|
88
|
-
),
|
89
|
-
sa.PrimaryKeyConstraint("id"),
|
90
|
-
)
|
91
|
-
op.create_table(
|
92
|
-
"provider_asset",
|
93
|
-
sa.Column("date", sa.Date(), nullable=False),
|
94
|
-
sa.Column("provider_id", sa.Integer(), nullable=False),
|
95
|
-
sa.Column("asset_id", sa.Integer(), nullable=False),
|
96
|
-
sa.Column("asset_code", sa.String(length=30), nullable=False),
|
97
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
98
|
-
sa.Column(
|
99
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
100
|
-
),
|
101
|
-
sa.Column(
|
102
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
103
|
-
),
|
104
|
-
sa.ForeignKeyConstraint(
|
105
|
-
["asset_id"],
|
106
|
-
["asset.id"],
|
107
|
-
),
|
108
|
-
sa.ForeignKeyConstraint(
|
109
|
-
["provider_id"],
|
110
|
-
["provider.id"],
|
111
|
-
),
|
112
|
-
sa.PrimaryKeyConstraint("date", "provider_id", "asset_id"),
|
113
|
-
)
|
114
|
-
op.create_table(
|
115
|
-
"provider_asset_order",
|
116
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
117
|
-
sa.Column("timestamp", sa.DateTime(), nullable=False),
|
118
|
-
sa.Column("provider_id", sa.Integer(), nullable=False),
|
119
|
-
sa.Column("from_asset_id", sa.Integer(), nullable=False),
|
120
|
-
sa.Column("to_asset_id", sa.Integer(), nullable=False),
|
121
|
-
sa.Column("price", sa.Float(), nullable=True),
|
122
|
-
sa.Column("volume", sa.Float(), nullable=True),
|
123
|
-
sa.ForeignKeyConstraint(
|
124
|
-
["from_asset_id"],
|
125
|
-
["asset.id"],
|
126
|
-
),
|
127
|
-
sa.ForeignKeyConstraint(
|
128
|
-
["provider_id"],
|
129
|
-
["provider.id"],
|
130
|
-
),
|
131
|
-
sa.ForeignKeyConstraint(
|
132
|
-
["to_asset_id"],
|
133
|
-
["asset.id"],
|
134
|
-
),
|
135
|
-
sa.PrimaryKeyConstraint("id"),
|
136
|
-
)
|
137
|
-
# ### end Alembic commands ###
|
138
|
-
|
139
|
-
|
140
|
-
def downgrade() -> None:
|
141
|
-
"""Downgrade schema."""
|
142
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
143
|
-
op.drop_table("provider_asset_order")
|
144
|
-
op.drop_table("provider_asset")
|
145
|
-
op.drop_table("provider")
|
146
|
-
op.drop_table("asset")
|
147
|
-
op.drop_table("provider_type")
|
148
|
-
op.drop_table("asset_type")
|
149
|
-
# ### end Alembic commands ###
|
@@ -1,114 +0,0 @@
|
|
1
|
-
"""Adding new market table and content tables.
|
2
|
-
|
3
|
-
Revision ID: 8b53c8e91507
|
4
|
-
Revises: 4056c087960a
|
5
|
-
Create Date: 2025-06-23 18:45:51.916364
|
6
|
-
|
7
|
-
"""
|
8
|
-
|
9
|
-
from typing import Sequence, Union
|
10
|
-
|
11
|
-
from alembic import op
|
12
|
-
import sqlalchemy as sa
|
13
|
-
|
14
|
-
|
15
|
-
# revision identifiers, used by Alembic.
|
16
|
-
revision: str = "8b53c8e91507"
|
17
|
-
down_revision: Union[str, Sequence[str], None] = "4056c087960a"
|
18
|
-
branch_labels: Union[str, Sequence[str], None] = None
|
19
|
-
depends_on: Union[str, Sequence[str], None] = None
|
20
|
-
|
21
|
-
|
22
|
-
def upgrade() -> None:
|
23
|
-
"""Upgrade schema."""
|
24
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
25
|
-
op.create_table(
|
26
|
-
"content_type",
|
27
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
28
|
-
sa.Column("name", sa.String(length=30), nullable=False),
|
29
|
-
sa.Column("description", sa.String(length=1000), nullable=True),
|
30
|
-
sa.Column("is_active", sa.Boolean(), nullable=False),
|
31
|
-
sa.Column(
|
32
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
33
|
-
),
|
34
|
-
sa.Column(
|
35
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
36
|
-
),
|
37
|
-
sa.PrimaryKeyConstraint("id"),
|
38
|
-
)
|
39
|
-
op.create_table(
|
40
|
-
"provider_asset_market",
|
41
|
-
sa.Column("timestamp", sa.DateTime(), nullable=False),
|
42
|
-
sa.Column("provider_id", sa.Integer(), nullable=False),
|
43
|
-
sa.Column("asset_id", sa.Integer(), nullable=False),
|
44
|
-
sa.Column("close", sa.Float(), nullable=True, comment="Closing price"),
|
45
|
-
sa.Column("open", sa.Float(), nullable=True, comment="Opening price"),
|
46
|
-
sa.Column("high", sa.Float(), nullable=True, comment="Highest price"),
|
47
|
-
sa.Column("low", sa.Float(), nullable=True, comment="Lowest price"),
|
48
|
-
sa.Column("volume", sa.Float(), nullable=True, comment="Volume traded"),
|
49
|
-
sa.Column("best_bid", sa.Float(), nullable=True, comment="Best bid price"),
|
50
|
-
sa.Column("best_ask", sa.Float(), nullable=True, comment="Best ask price"),
|
51
|
-
sa.ForeignKeyConstraint(
|
52
|
-
["asset_id"],
|
53
|
-
["asset.id"],
|
54
|
-
),
|
55
|
-
sa.ForeignKeyConstraint(
|
56
|
-
["provider_id"],
|
57
|
-
["provider.id"],
|
58
|
-
),
|
59
|
-
sa.PrimaryKeyConstraint("timestamp", "provider_id", "asset_id"),
|
60
|
-
)
|
61
|
-
op.create_table(
|
62
|
-
"provider_content",
|
63
|
-
sa.Column("id", sa.Integer(), nullable=False),
|
64
|
-
sa.Column("timestamp", sa.DateTime(), nullable=False),
|
65
|
-
sa.Column("provider_id", sa.Integer(), nullable=False),
|
66
|
-
sa.Column("provider_unique_identifier", sa.String(length=1000), nullable=False),
|
67
|
-
sa.Column("content_type_id", sa.Integer(), nullable=False),
|
68
|
-
sa.Column("author", sa.String(length=100), nullable=True),
|
69
|
-
sa.Column("title", sa.String(length=200), nullable=True),
|
70
|
-
sa.Column("content", sa.String(), nullable=False),
|
71
|
-
sa.Column(
|
72
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
73
|
-
),
|
74
|
-
sa.Column(
|
75
|
-
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
76
|
-
),
|
77
|
-
sa.ForeignKeyConstraint(
|
78
|
-
["content_type_id"],
|
79
|
-
["content_type.id"],
|
80
|
-
),
|
81
|
-
sa.ForeignKeyConstraint(
|
82
|
-
["provider_id"],
|
83
|
-
["provider.id"],
|
84
|
-
),
|
85
|
-
sa.PrimaryKeyConstraint("id"),
|
86
|
-
)
|
87
|
-
op.create_table(
|
88
|
-
"asset_content",
|
89
|
-
sa.Column("content_id", sa.Integer(), nullable=False),
|
90
|
-
sa.Column("asset_id", sa.Integer(), nullable=False),
|
91
|
-
sa.Column(
|
92
|
-
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
93
|
-
),
|
94
|
-
sa.ForeignKeyConstraint(
|
95
|
-
["asset_id"],
|
96
|
-
["asset.id"],
|
97
|
-
),
|
98
|
-
sa.ForeignKeyConstraint(
|
99
|
-
["content_id"],
|
100
|
-
["provider_content.id"],
|
101
|
-
),
|
102
|
-
sa.PrimaryKeyConstraint("content_id", "asset_id"),
|
103
|
-
)
|
104
|
-
# ### end Alembic commands ###
|
105
|
-
|
106
|
-
|
107
|
-
def downgrade() -> None:
|
108
|
-
"""Downgrade schema."""
|
109
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
110
|
-
op.drop_table("asset_content")
|
111
|
-
op.drop_table("provider_content")
|
112
|
-
op.drop_table("provider_asset_market")
|
113
|
-
op.drop_table("content_type")
|
114
|
-
# ### end Alembic commands ###
|
@@ -1,7 +0,0 @@
|
|
1
|
-
alembic/env.py,sha256=31tHj84uXsP2MQvhcwgbXGEzN40P_lS3n7jHQSlbtnU,2373
|
2
|
-
alembic/versions/4056c087960a_.py,sha256=-w5OvJcx0Oct_KpFsoG9j0EHiuPJI9e6yjaIjhg0BBY,5278
|
3
|
-
alembic/versions/8b53c8e91507_adding_new_market_table_and_content_.py,sha256=2_TnumPJi-zLJKag4T0f4kDy2wscMmFI6ydqEcSuLXw,4226
|
4
|
-
mc_postgres_db-0.1.0.dist-info/METADATA,sha256=UVZLGeo8RCMbRMB_91AbyrAQsnUfX-jo9A4e_UESAJA,282
|
5
|
-
mc_postgres_db-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
mc_postgres_db-0.1.0.dist-info/top_level.txt,sha256=FwKWd5VsPFC8iQjpu1u9Cn-JnK3-V1RhUCmWqz1cl-s,8
|
7
|
-
mc_postgres_db-0.1.0.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
alembic
|
File without changes
|