xync-schema 0.0.54.dev3__tar.gz

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.
@@ -0,0 +1,2 @@
1
+ DB_URL=postgres://user:password@host/db_name
2
+ VENV=.venv
@@ -0,0 +1,7 @@
1
+ /.idea/
2
+ /*.egg-info
3
+ /dist
4
+ /.env
5
+ /venv
6
+ __pycache__
7
+ /build
@@ -0,0 +1,44 @@
1
+ repos:
2
+ - repo: local
3
+ hooks:
4
+ - id: pytest
5
+ name: pytest
6
+ entry: pytest tests -v
7
+ language: python
8
+ types: [python]
9
+ verbose: true
10
+ stages: [pre-commit]
11
+
12
+ - id: tag
13
+ name: tag
14
+ ### make tag with next ver only if "fix" in commit_msg or starts with "feat"
15
+ entry: bash -c 'grep -e "^feat:" -e "^fix:" .git/COMMIT_EDITMSG && make patch || exit 0'
16
+ language: system
17
+ verbose: true
18
+ pass_filenames: false
19
+ always_run: true
20
+ stages: [post-commit]
21
+
22
+ - id: build
23
+ name: build
24
+ ### build & upload package only for "main" branch push
25
+ entry: bash -c 'echo $PRE_COMMIT_LOCAL_BRANCH | grep /main && make twine || echo 0'
26
+ language: system
27
+ pass_filenames: false
28
+ verbose: true
29
+ require_serial: true
30
+ stages: [pre-push]
31
+
32
+ - repo: https://github.com/astral-sh/ruff-pre-commit
33
+ ### Ruff version.
34
+ rev: v0.14.4
35
+ hooks:
36
+ ### Run the linter.
37
+ - id: ruff
38
+ args: [--fix]
39
+ stages: [pre-commit]
40
+ ### Run the formatter.
41
+ - id: ruff-format
42
+ types_or: [python, pyi]
43
+ verbose: true
44
+ stages: [pre-commit]
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: xync-schema
3
+ Version: 0.0.54.dev3
4
+ Summary: XyncNet project database model schema
5
+ Author-email: Mike Artemiev <mixartemev@gmail.com>
6
+ License: EULA
7
+ Project-URL: Homepage, https://gitlab.com/xync/back/schema
8
+ Project-URL: Repository, https://gitlab.com/xync/back/schema
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: aerich
12
+ Requires-Dist: xn-auth
13
+ Provides-Extra: dev
14
+ Requires-Dist: build; extra == "dev"
15
+ Requires-Dist: pre-commit; extra == "dev"
16
+ Requires-Dist: pytest-asyncio; extra == "dev"
17
+ Requires-Dist: python-dotenv; extra == "dev"
18
+ Requires-Dist: setuptools-scm[toml]; extra == "dev"
19
+ Requires-Dist: twine; extra == "dev"
20
+
21
+ ## INSTALL
22
+ ```bash
23
+ # Create python virtual environment
24
+ python3 -m venv venv
25
+ # Activate this environment
26
+ source venv/bin/activate
27
+ # Install dependencies
28
+ pip install -r requirements.dev.txt
29
+
30
+ # Create pg db
31
+ createdb --U username -W dbname
32
+ ## set password for db user
33
+
34
+ # Copy .env file from sample template
35
+ cp .env.sample .env
36
+ ## set your pg creds in .env file
37
+ ```
38
+
39
+ ## TEST
40
+ ```bash
41
+ pytest
42
+ ```
43
+
44
+
45
+ ### pre-commit
46
+ You can done `commit` only after `pytest` will done success.
47
+ Pre-commit script stored in `.git/hooks/pre-commit` file; current script is:
48
+ ```shell
49
+ #!/bin/sh
50
+ pytest
51
+ ```
52
+
53
+ ### Relations
54
+ ```mermaid
55
+ classDiagram
56
+ direction BT
57
+ class Agent {
58
+ timestamp(0) with time zone created_at
59
+ timestamp(0) with time zone updated_at
60
+ integer exid
61
+ jsonb auth
62
+ smallint ex_id
63
+ bigint user_id
64
+ integer id
65
+ }
66
+ class Asset {
67
+ smallint type_ /* spot: 1\nearn: 2\nfound: 3 */
68
+ double precision free
69
+ double precision freeze
70
+ double precision lock
71
+ double precision target
72
+ integer agent_id
73
+ smallint coin_id
74
+ integer id
75
+ }
76
+ class Coin {
77
+ varchar(15) ticker
78
+ double precision rate
79
+ boolean is_fiat
80
+ smallint id
81
+ }
82
+ class CoinEx {
83
+ varchar(31) exid
84
+ boolean p2p
85
+ smallint coin_id
86
+ smallint ex_id
87
+ integer id
88
+ }
89
+ class Cur {
90
+ varchar(3) ticker
91
+ double precision rate
92
+ smallint id
93
+ }
94
+ class CurEx {
95
+ varchar(31) exid
96
+ boolean p2p
97
+ smallint cur_id
98
+ smallint ex_id
99
+ integer id
100
+ }
101
+ class Ex {
102
+ varchar(31) name
103
+ varchar(63) host /* With no protocol 'https://' */
104
+ varchar(63) host_p2p /* With no protocol 'https://' */
105
+ varchar(63) url_login /* With no protocol 'https://' */
106
+ smallint type_ /* p2p: 1\ncex: 2\nmain: 3\ndex: 4\nfutures: 8 */
107
+ varchar(511) logo
108
+ smallint id
109
+ }
110
+ class Fiat {
111
+ varchar(127) detail
112
+ varchar(127) name
113
+ double precision amount
114
+ double precision target
115
+ integer pmcur_id
116
+ bigint user_id
117
+ integer id
118
+ }
119
+ class FiatEx {
120
+ integer exid
121
+ smallint ex_id
122
+ integer fiat_id
123
+ integer id
124
+ }
125
+ class Limit {
126
+ integer amount
127
+ integer unit
128
+ integer level
129
+ boolean income
130
+ bigint added_by_id
131
+ integer pmcur_id
132
+ integer id
133
+ }
134
+ class Pm {
135
+ varchar(63) name
136
+ smallint rank
137
+ smallint type_ /* bank: 0\nweb_wallet: 1\ncash: 2\ngift_card: 3\ncredit_card: 4 */
138
+ varchar(127) logo
139
+ boolean multiAllow
140
+ integer id
141
+ }
142
+ class PmCur {
143
+ smallint cur_id
144
+ integer pm_id
145
+ integer id
146
+ }
147
+ class PmCurEx {
148
+ boolean blocked
149
+ smallint ex_id
150
+ integer pmcur_id
151
+ integer id
152
+ }
153
+ class PmEx {
154
+ varchar(31) exid
155
+ smallint ex_id
156
+ integer pm_id
157
+ integer id
158
+ }
159
+ class User {
160
+ timestamp(0) with time zone created_at
161
+ timestamp(0) with time zone updated_at
162
+ smallint role /* READER: 4\nWRITER: 2\nMANAGER: 6\nADMIN: 7 */
163
+ smallint status /* CREATOR: 5\nADMINISTRATOR: 4\nMEMBER: 3\nRESTRICTED: 2\nLEFT:... */
164
+ varchar(95) username
165
+ bigint ref_id
166
+ bigint id
167
+ }
168
+
169
+ Agent --> Ex : ex_id-id
170
+ Agent --> User : user_id-id
171
+ Asset --> Agent : agent_id-id
172
+ Asset --> Coin : coin_id-id
173
+ CoinEx --> Coin : coin_id-id
174
+ CoinEx --> Ex : ex_id-id
175
+ CurEx --> Cur : cur_id-id
176
+ CurEx --> Ex : ex_id-id
177
+ Fiat --> PmCur : pmcur_id-id
178
+ Fiat --> User : user_id-id
179
+ FiatEx --> Ex : ex_id-id
180
+ FiatEx --> Fiat : fiat_id-id
181
+ Limit --> PmCur : pmcur_id-id
182
+ Limit --> User : added_by_id-id
183
+ PmCur --> Cur : cur_id-id
184
+ PmCur --> Pm : pm_id-id
185
+ PmCurEx --> Ex : ex_id-id
186
+ PmCurEx --> PmCur : pmcur_id-id
187
+ PmEx --> Ex : ex_id-id
188
+ PmEx --> Pm : pm_id-id
189
+ User --> User : ref_id-id
190
+ ```
@@ -0,0 +1,170 @@
1
+ ## INSTALL
2
+ ```bash
3
+ # Create python virtual environment
4
+ python3 -m venv venv
5
+ # Activate this environment
6
+ source venv/bin/activate
7
+ # Install dependencies
8
+ pip install -r requirements.dev.txt
9
+
10
+ # Create pg db
11
+ createdb --U username -W dbname
12
+ ## set password for db user
13
+
14
+ # Copy .env file from sample template
15
+ cp .env.sample .env
16
+ ## set your pg creds in .env file
17
+ ```
18
+
19
+ ## TEST
20
+ ```bash
21
+ pytest
22
+ ```
23
+
24
+
25
+ ### pre-commit
26
+ You can done `commit` only after `pytest` will done success.
27
+ Pre-commit script stored in `.git/hooks/pre-commit` file; current script is:
28
+ ```shell
29
+ #!/bin/sh
30
+ pytest
31
+ ```
32
+
33
+ ### Relations
34
+ ```mermaid
35
+ classDiagram
36
+ direction BT
37
+ class Agent {
38
+ timestamp(0) with time zone created_at
39
+ timestamp(0) with time zone updated_at
40
+ integer exid
41
+ jsonb auth
42
+ smallint ex_id
43
+ bigint user_id
44
+ integer id
45
+ }
46
+ class Asset {
47
+ smallint type_ /* spot: 1\nearn: 2\nfound: 3 */
48
+ double precision free
49
+ double precision freeze
50
+ double precision lock
51
+ double precision target
52
+ integer agent_id
53
+ smallint coin_id
54
+ integer id
55
+ }
56
+ class Coin {
57
+ varchar(15) ticker
58
+ double precision rate
59
+ boolean is_fiat
60
+ smallint id
61
+ }
62
+ class CoinEx {
63
+ varchar(31) exid
64
+ boolean p2p
65
+ smallint coin_id
66
+ smallint ex_id
67
+ integer id
68
+ }
69
+ class Cur {
70
+ varchar(3) ticker
71
+ double precision rate
72
+ smallint id
73
+ }
74
+ class CurEx {
75
+ varchar(31) exid
76
+ boolean p2p
77
+ smallint cur_id
78
+ smallint ex_id
79
+ integer id
80
+ }
81
+ class Ex {
82
+ varchar(31) name
83
+ varchar(63) host /* With no protocol 'https://' */
84
+ varchar(63) host_p2p /* With no protocol 'https://' */
85
+ varchar(63) url_login /* With no protocol 'https://' */
86
+ smallint type_ /* p2p: 1\ncex: 2\nmain: 3\ndex: 4\nfutures: 8 */
87
+ varchar(511) logo
88
+ smallint id
89
+ }
90
+ class Fiat {
91
+ varchar(127) detail
92
+ varchar(127) name
93
+ double precision amount
94
+ double precision target
95
+ integer pmcur_id
96
+ bigint user_id
97
+ integer id
98
+ }
99
+ class FiatEx {
100
+ integer exid
101
+ smallint ex_id
102
+ integer fiat_id
103
+ integer id
104
+ }
105
+ class Limit {
106
+ integer amount
107
+ integer unit
108
+ integer level
109
+ boolean income
110
+ bigint added_by_id
111
+ integer pmcur_id
112
+ integer id
113
+ }
114
+ class Pm {
115
+ varchar(63) name
116
+ smallint rank
117
+ smallint type_ /* bank: 0\nweb_wallet: 1\ncash: 2\ngift_card: 3\ncredit_card: 4 */
118
+ varchar(127) logo
119
+ boolean multiAllow
120
+ integer id
121
+ }
122
+ class PmCur {
123
+ smallint cur_id
124
+ integer pm_id
125
+ integer id
126
+ }
127
+ class PmCurEx {
128
+ boolean blocked
129
+ smallint ex_id
130
+ integer pmcur_id
131
+ integer id
132
+ }
133
+ class PmEx {
134
+ varchar(31) exid
135
+ smallint ex_id
136
+ integer pm_id
137
+ integer id
138
+ }
139
+ class User {
140
+ timestamp(0) with time zone created_at
141
+ timestamp(0) with time zone updated_at
142
+ smallint role /* READER: 4\nWRITER: 2\nMANAGER: 6\nADMIN: 7 */
143
+ smallint status /* CREATOR: 5\nADMINISTRATOR: 4\nMEMBER: 3\nRESTRICTED: 2\nLEFT:... */
144
+ varchar(95) username
145
+ bigint ref_id
146
+ bigint id
147
+ }
148
+
149
+ Agent --> Ex : ex_id-id
150
+ Agent --> User : user_id-id
151
+ Asset --> Agent : agent_id-id
152
+ Asset --> Coin : coin_id-id
153
+ CoinEx --> Coin : coin_id-id
154
+ CoinEx --> Ex : ex_id-id
155
+ CurEx --> Cur : cur_id-id
156
+ CurEx --> Ex : ex_id-id
157
+ Fiat --> PmCur : pmcur_id-id
158
+ Fiat --> User : user_id-id
159
+ FiatEx --> Ex : ex_id-id
160
+ FiatEx --> Fiat : fiat_id-id
161
+ Limit --> PmCur : pmcur_id-id
162
+ Limit --> User : added_by_id-id
163
+ PmCur --> Cur : cur_id-id
164
+ PmCur --> Pm : pm_id-id
165
+ PmCurEx --> Ex : ex_id-id
166
+ PmCurEx --> PmCur : pmcur_id-id
167
+ PmEx --> Ex : ex_id-id
168
+ PmEx --> Pm : pm_id-id
169
+ User --> User : ref_id-id
170
+ ```
@@ -0,0 +1,27 @@
1
+ include .env
2
+ PACKAGE := xync_schema
3
+ VPYTHON := $(VENV)/bin/python
4
+
5
+ .PHONY: all install pre-commit test clean build twine patch
6
+
7
+ all:
8
+ make install test clean build
9
+
10
+ install: $(VENV)
11
+ $(VPYTHON) -m pip install -e .[dev]; make pre-commit
12
+ pre-commit: .pre-commit-config.yaml
13
+ pre-commit install -t pre-commit -t post-commit -t pre-push
14
+
15
+ test:
16
+ $(VPYTHON) -m pytest
17
+
18
+ clean: .pytest_cache dist $(PACKAGE).egg-info
19
+ rm -rf .pytest_cache dist/* $(PACKAGE).egg-info $(PACKAGE)/__pycache__ dist/__pycache__
20
+
21
+ build:
22
+ $(VPYTHON) -m build
23
+ twine: build dist
24
+ $(VPYTHON) -m twine upload dist/* --skip-existing
25
+
26
+ patch:
27
+ git tag `$(VPYTHON) -m setuptools_scm --strip-dev`; git push --tags --prune -f
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "xync-schema"
3
+ requires-python = ">=3.11"
4
+ authors = [
5
+ {name = "Mike Artemiev", email = "mixartemev@gmail.com"},
6
+ ]
7
+ description = "XyncNet project database model schema"
8
+ readme = "README.md"
9
+ license = {text = "EULA"}
10
+ dynamic = ["version"]
11
+
12
+ dependencies = [
13
+ "aerich",
14
+ "xn-auth",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ dev = [
19
+ "build",
20
+ "pre-commit",
21
+ "pytest-asyncio",
22
+ "python-dotenv",
23
+ "setuptools-scm[toml]",
24
+ "twine",
25
+ ]
26
+ [project.urls]
27
+ Homepage = "https://gitlab.com/xync/back/schema"
28
+ Repository = "https://gitlab.com/xync/back/schema"
29
+
30
+ [build-system]
31
+ requires = ["setuptools>=64", "setuptools-scm[toml]>=8"]
32
+ build-backend = "setuptools.build_meta"
33
+ [tool.setuptools_scm]
34
+ version_scheme = "python-simplified-semver" # if "feature" in `branch_name` SEMVER_MINOR++ else SEMVER_PATCH++
35
+ local_scheme = "no-local-version"
36
+
37
+ [tool.setuptools]
38
+ packages = ["xync_schema"]
39
+
40
+ [tool.pytest.ini_options]
41
+ asyncio_mode = "auto"
42
+ asyncio_default_fixture_loop_scope = "function"
43
+
44
+ [tool.ruff]
45
+ line-length = 120
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,24 @@
1
+ import pytest
2
+ from dotenv import load_dotenv
3
+ from tortoise.backends.asyncpg import AsyncpgDBClient
4
+ from x_model import init_db
5
+
6
+ from xync_schema import TORM
7
+
8
+ load_dotenv()
9
+
10
+
11
+ @pytest.fixture
12
+ async def _dbc() -> AsyncpgDBClient:
13
+ cn: AsyncpgDBClient = await init_db(TORM, True)
14
+ yield cn
15
+ await cn.close()
16
+
17
+
18
+ async def test_init_db(_dbc):
19
+ assert isinstance(_dbc, AsyncpgDBClient), "DB corrupt"
20
+
21
+
22
+ # async def test_models(_dbc):
23
+ # c = await models.Ex.first()
24
+ # assert isinstance(c, models.Ex), "No exs"
@@ -0,0 +1,28 @@
1
+ from os import getenv as env
2
+ from dotenv import load_dotenv
3
+
4
+ from xync_schema import models
5
+
6
+ load_dotenv()
7
+
8
+ TORM = {
9
+ "connections": {"default": env("DB_URL")},
10
+ "apps": {"models": {"models": [models, "aerich.models"]}},
11
+ "use_tz": False,
12
+ "timezone": "UTC",
13
+ }
14
+
15
+
16
+ async def main():
17
+ import logging
18
+ from x_model import init_db
19
+ from logging import DEBUG
20
+
21
+ logging.basicConfig(level=DEBUG)
22
+ await init_db(TORM, True)
23
+
24
+
25
+ if __name__ == "__main__":
26
+ from asyncio import run
27
+
28
+ run(main())