Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
google_drive
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Мырзабеков Бекайдар
google_drive
Commits
b4e19ce9
Commit
b4e19ce9
authored
Dec 17, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added models and migrations
parent
aaa8da24
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
0 deletions
+116
-0
pyproject.toml
pyproject.toml
+5
-0
base.py
src/app/db/base.py
+23
-0
models.py
src/app/db/models.py
+41
-0
0_20231217180851_init.py
src/migrations/models/0_20231217180851_init.py
+47
-0
No files found.
pyproject.toml
View file @
b4e19ce9
...
@@ -16,6 +16,11 @@ asyncpg = "^0.29.0"
...
@@ -16,6 +16,11 @@ asyncpg = "^0.29.0"
aerich
=
"^0.7.2"
aerich
=
"^0.7.2"
[tool.aerich]
tortoise_orm
=
"src.app.db.conf.TORTOISE_ORM"
location
=
"src/migrations"
src_folder
=
"./."
[build-system]
[build-system]
requires
=
["poetry-core"]
requires
=
["poetry-core"]
build-backend
=
"poetry.core.masonry.api"
build-backend
=
"poetry.core.masonry.api"
src/app/db/base.py
0 → 100644
View file @
b4e19ce9
from
uuid
import
uuid4
from
tortoise
import
fields
,
models
class
IdMixin
(
models
.
Model
):
id
=
fields
.
UUIDField
(
pk
=
True
,
default
=
uuid4
)
class
Meta
:
abstract
=
True
class
TimestampMixin
(
models
.
Model
):
created_at
=
fields
.
DatetimeField
(
auto_now_add
=
True
)
updated_at
=
fields
.
DatetimeField
(
auto_now
=
True
)
class
Meta
:
abstract
=
True
class
BaseModel
(
IdMixin
,
TimestampMixin
):
class
Meta
:
ordering
=
(
'-created_at'
,
)
src/app/db/models.py
View file @
b4e19ce9
from
tortoise
import
fields
from
.base
import
BaseModel
class
User
(
BaseModel
):
username
=
fields
.
CharField
(
max_length
=
50
,
unique
=
True
)
name
=
fields
.
CharField
(
max_length
=
50
)
surname
=
fields
.
CharField
(
max_length
=
50
)
email
=
fields
.
CharField
(
max_length
=
50
)
password
=
fields
.
CharField
(
max_length
=
100
)
def
__str__
(
self
):
return
f
'{self.surname} {self.name}'
class
Meta
(
BaseModel
.
Meta
):
table
=
'users'
class
Folder
(
BaseModel
):
name
=
fields
.
CharField
(
max_length
=
50
)
user
=
fields
.
ForeignKeyField
(
"models.User"
,
related_name
=
"user_folders"
)
def
__str__
(
self
):
return
self
.
name
class
Meta
(
BaseModel
.
Meta
):
table
=
'folders'
class
File
(
BaseModel
):
name
=
fields
.
CharField
(
max_length
=
50
)
content
=
fields
.
TextField
()
user
=
fields
.
ForeignKeyField
(
"models.User"
,
related_name
=
"user_files"
)
folder
=
fields
.
ForeignKeyField
(
"models.Folder"
,
related_name
=
"folder_files"
,
null
=
True
)
def
__str__
(
self
):
return
self
.
name
class
Meta
(
BaseModel
.
Meta
):
table
=
'files'
src/migrations/models/0_20231217180851_init.py
0 → 100644
View file @
b4e19ce9
from
tortoise
import
BaseDBAsyncClient
async
def
upgrade
(
db
:
BaseDBAsyncClient
)
->
str
:
return
"""
CREATE TABLE IF NOT EXISTS "basemodel" (
"id" UUID NOT NULL PRIMARY KEY,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS "users" (
"id" UUID NOT NULL PRIMARY KEY,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"username" VARCHAR(50) NOT NULL UNIQUE,
"name" VARCHAR(50) NOT NULL,
"surname" VARCHAR(50) NOT NULL,
"email" VARCHAR(50) NOT NULL,
"password" VARCHAR(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS "folders" (
"id" UUID NOT NULL PRIMARY KEY,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" VARCHAR(50) NOT NULL,
"user_id" UUID NOT NULL REFERENCES "users" ("id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "files" (
"id" UUID NOT NULL PRIMARY KEY,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" VARCHAR(50) NOT NULL,
"content" TEXT NOT NULL,
"folder_id" UUID REFERENCES "folders" ("id") ON DELETE CASCADE,
"user_id" UUID NOT NULL REFERENCES "users" ("id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "aerich" (
"id" SERIAL NOT NULL PRIMARY KEY,
"version" VARCHAR(255) NOT NULL,
"app" VARCHAR(100) NOT NULL,
"content" JSONB NOT NULL
);"""
async
def
downgrade
(
db
:
BaseDBAsyncClient
)
->
str
:
return
"""
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment