Updated tables, changed primary keys

Removed id fields from tables
Set user_id to be primary key of master_passwords
Set user_id and name to be primary keys of accounts
This commit is contained in:
StNicolay 2022-12-10 23:46:00 +03:00
parent 9690db982e
commit a9417058ee

View File

@ -1,12 +1,11 @@
from typing import Optional
import sqlmodel import sqlmodel
class MasterPass(sqlmodel.SQLModel, table=True): class MasterPass(sqlmodel.SQLModel, table=True):
__tablename__ = "master_passwords" __tablename__ = "master_passwords"
id: Optional[int] = sqlmodel.Field(primary_key=True) user_id: int = sqlmodel.Field(
user_id: int = sqlmodel.Field(nullable=False, index=True, unique=True) sa_column=sqlmodel.Column(sqlmodel.INT(), primary_key=True)
)
salt: bytes = sqlmodel.Field( salt: bytes = sqlmodel.Field(
sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False) sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False)
) )
@ -17,10 +16,9 @@ class MasterPass(sqlmodel.SQLModel, table=True):
class Account(sqlmodel.SQLModel, table=True): class Account(sqlmodel.SQLModel, table=True):
__tablename__ = "accounts" __tablename__ = "accounts"
__table_args__ = (sqlmodel.UniqueConstraint("user_id", "name"),) __table_args__ = (sqlmodel.PrimaryKeyConstraint("user_id", "name"),)
id: Optional[int] = sqlmodel.Field(primary_key=True) user_id: int = sqlmodel.Field()
user_id: int = sqlmodel.Field(nullable=False, index=True) name: str = sqlmodel.Field(max_length=255)
name: str = sqlmodel.Field(nullable=False, index=True, max_length=255)
salt: bytes = sqlmodel.Field( salt: bytes = sqlmodel.Field(
sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False) sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False)
) )