Shri commited on
Commit
5a5f1de
·
1 Parent(s): ce1e080

base db created

Browse files
.gitignore CHANGED
@@ -1,3 +1,3 @@
1
- __pycache__
2
  venv/
3
  .env
 
1
+ __pycache__/
2
  venv/
3
  .env
.idea/.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
.idea/dataSources.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
4
+ <data-source source="LOCAL" name="[email protected]" uuid="1721f11c-8c2c-4f79-8cb4-ae21650c04d7">
5
+ <driver-ref>postgresql</driver-ref>
6
+ <synchronize>true</synchronize>
7
+ <jdbc-driver>org.postgresql.Driver</jdbc-driver>
8
+ <jdbc-url>jdbc:postgresql://ep-solitary-dew-a4ljqdib-pooler.us-east-1.aws.neon.tech:5432/neondb</jdbc-url>
9
+ <working-dir>$ProjectFileDir$</working-dir>
10
+ </data-source>
11
+ </component>
12
+ </project>
.idea/data_source_mapping.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="DataSourcePerFileMappings">
4
+ <file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/1721f11c-8c2c-4f79-8cb4-ae21650c04d7/console.sql" value="1721f11c-8c2c-4f79-8cb4-ae21650c04d7" />
5
+ </component>
6
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/yuvabe-app-backend.iml" filepath="$PROJECT_DIR$/.idea/yuvabe-app-backend.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/sqldialects.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="SqlDialectMappings">
4
+ <file url="PROJECT" dialect="PostgreSQL" />
5
+ </component>
6
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
.idea/yuvabe-app-backend.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="DBE_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
src/auth/__init__.py ADDED
File without changes
src/chatbot/__init__.py ADDED
File without changes
src/core/__init__.py ADDED
File without changes
src/core/database.py CHANGED
@@ -1,10 +1,21 @@
1
- from sqlmodel import SQLModel, create_engine
2
- from dotenv import load_dotenv
3
- from . import models
4
  import os
5
 
 
 
 
 
 
 
6
  load_dotenv()
7
 
8
- engine = create_engine(os.getenv('DATABASE_URL'),echo=True)
 
 
 
 
 
9
 
10
- SQLModel.metadata.create_all(engine)
 
 
 
 
 
 
 
1
  import os
2
 
3
+ from dotenv import load_dotenv
4
+ from sqlmodel import SQLModel, create_engine
5
+
6
+ from src.core import models as core_models
7
+ from src.feed import models as feed_models
8
+
9
  load_dotenv()
10
 
11
+ engine = create_engine(os.getenv("DATABASE_URL"), echo=True)
12
+
13
+
14
+ def init_db():
15
+ SQLModel.metadata.create_all(engine)
16
+
17
 
18
+ if __name__ == "__main__":
19
+ print("Table creating")
20
+ init_db()
21
+ print("Table Created successfully!")
src/core/insert_sample.py DELETED
@@ -1,40 +0,0 @@
1
- from sqlmodel import Session
2
- from datetime import date
3
- import uuid
4
-
5
- from src.core.database import engine
6
- from src.core.models import Users, Roles, Teams
7
-
8
-
9
- role = Roles(
10
- id=uuid.uuid4(),
11
- name="User"
12
- )
13
-
14
- team = Teams(
15
- id=uuid.uuid4(),
16
- name="Health Squad"
17
- )
18
-
19
- user = Users(
20
- id=uuid.uuid4(),
21
- email_id="[email protected]",
22
- password="hashed_password_here",
23
- user_name="tilak",
24
- dob=date(2000, 5, 20),
25
- address="Bangalore, India",
26
- role_id=role.id,
27
- emotion_trend={"happy": 10, "sad": 2},
28
- habit_trend={"exercise": 5, "sleep": 8},
29
- profile_picture="https://example.com/image.jpg",
30
- post_id=uuid.uuid4()
31
- )
32
-
33
-
34
- with Session(engine) as session:
35
- session.add(role)
36
- session.add(team)
37
- session.add(user)
38
- session.commit()
39
-
40
- print("Sample data inserted successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/core/models.py CHANGED
@@ -1,25 +1,71 @@
1
- from sqlmodel import SQLModel, Field
2
- from datetime import date
3
- from sqlalchemy.dialects.postgresql import JSONB
4
  import uuid
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  class Users(SQLModel, table=True):
7
- id: uuid.UUID | None = Field(default=None, primary_key=True)
8
- email_id : str = Field(unique=True)
9
- password : str
10
- user_name : str
11
- dob : date
12
- address : str
13
- role_id : uuid.UUID
14
- emotion_trend : dict = Field(sa_type=JSONB)
15
- habit_trend : dict = Field(sa_type=JSONB)
16
- profile_picture : str
17
- post_id : uuid.UUID
18
-
19
- class Teams(SQLModel, table = True):
20
- id: uuid.UUID | None = Field(default=None, primary_key=True)
21
- name : str
22
-
23
- class Roles(SQLModel, table = True):
24
- id : uuid.UUID | None = Field(default=None , primary_key=True)
25
- name : str
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import uuid
2
+ from datetime import date, datetime
3
+ from enum import Enum
4
+ from typing import List, Optional
5
+
6
+ from sqlalchemy import CheckConstraint, UniqueConstraint
7
+ from sqlmodel import Field, Relationship, SQLModel
8
+
9
+
10
+ class AssetStatus(str, Enum):
11
+ ACTIVE = "Active"
12
+ UNAVAILABLE = "Unavailable"
13
+ ON_REQUEST = "On Request"
14
+ IN_SERVICE = "In Service"
15
+
16
 
17
  class Users(SQLModel, table=True):
18
+ __tablename__ = "users"
19
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
20
+ email_id: str = Field(unique=True, nullable=False)
21
+ password: str = Field(nullable=False)
22
+ user_name: str = Field(nullable=False)
23
+ dob: Optional[date] = None
24
+ address: Optional[str] = None
25
+ profile_picture: Optional[str] = None
26
+ created_at: datetime = Field(default=datetime.now)
27
+ asset: List["Assets"] = Relationship(back_populates="user")
28
+
29
+
30
+ class Teams(SQLModel, table=True):
31
+ __tablename__ = "teams"
32
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
33
+ name: str = Field(unique=True, nullable=False)
34
+
35
+
36
+ class Roles(SQLModel, table=True):
37
+ __tablename__ = "roles"
38
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
39
+ name: str = Field(unique=True, nullable=False)
40
+
41
+
42
+ class UserTeamsRole(SQLModel, table=True):
43
+ __tablename__ = "user_teams_role"
44
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
45
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
46
+ team_id: uuid.UUID = Field(foreign_key="teams.id", nullable=False)
47
+ role_id: uuid.UUID = Field(foreign_key="roles.id", nullable=False)
48
+
49
+
50
+ class Assets(SQLModel, table=True):
51
+ __tablename__ = "assets"
52
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
53
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
54
+ name: str = Field(nullable=False)
55
+ type: str = Field(nullable=False)
56
+ status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
57
+ user: "Users" = Relationship(back_populates="asset")
58
+
59
+
60
+ class EmotionLogs(SQLModel, table=True):
61
+ __tablename__ = "emotion_logs"
62
+ __table_args__ = (
63
+ UniqueConstraint("user_id", "log_date"),
64
+ CheckConstraint("morning_emotion BETWEEN 1 AND 10 or morning_emotion IS NULL"),
65
+ CheckConstraint("evening_emotion BETWEEN 1 AND 10 or evening_emotion IS NULL"),
66
+ )
67
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
68
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
69
+ morning_emotion: Optional[int] = Field(default=None, ge=1, le=10)
70
+ evening_emotion: Optional[int] = Field(default=None, ge=1, le=10)
71
+ log_date: date = Field(default_factory=date.today)
src/feed/__init__.py ADDED
File without changes
src/feed/models.py CHANGED
@@ -1,2 +1,49 @@
1
  import uuid
2
- import sqlmodel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import uuid
2
+ from datetime import datetime
3
+ from enum import Enum
4
+ from typing import Optional
5
+
6
+ from sqlalchemy import UniqueConstraint
7
+ from sqlmodel import Field, SQLModel
8
+
9
+
10
+ class PostType(str, Enum):
11
+ BIRTHDAY = "Birthday"
12
+ NOTICE = "Notice"
13
+ BANNER = "Banner"
14
+ JOB_REQUEST = "Job Request"
15
+
16
+
17
+ class PostCategory(str, Enum):
18
+ TEAM = "Team"
19
+ GLOBAL = "Global"
20
+
21
+
22
+ class Posts(SQLModel, table=True):
23
+ __tablename__ = "posts"
24
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
25
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
26
+ type: PostType = Field(default=PostType.NOTICE)
27
+ category: PostCategory = Field(default=PostCategory.GLOBAL)
28
+ caption: Optional[str] = None
29
+ image: Optional[str] = None
30
+ created_at: datetime = Field(default=datetime.now, nullable=False)
31
+ edited_at: datetime = Field(default_factory=datetime.now)
32
+
33
+
34
+ class Comments(SQLModel, table=True):
35
+ __tablename__ = "comments"
36
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
37
+ post_id: uuid.UUID = Field(foreign_key="posts.id", nullable=False)
38
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
39
+ comment: str = Field(nullable=False)
40
+ created_at: datetime = Field(default=datetime.now, nullable=False)
41
+
42
+
43
+ class Likes(SQLModel, table=True):
44
+ __tablename__ = "likes"
45
+ __table_args__ = (UniqueConstraint("user_id", "post_id"),)
46
+ id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
47
+ post_id: uuid.UUID = Field(foreign_key="posts.id", nullable=False)
48
+ user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
49
+ liked_at: datetime = Field(default=datetime.now, nullable=False)
src/home/__init__.py ADDED
File without changes
src/profile/__init__.py ADDED
File without changes