Skip to content

Feature/limit submodule #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4501aff
first commit
jaanbaaz Dec 4, 2024
cb8c194
Initial setup commit
jaanbaaz Dec 4, 2024
f6cb9cc
Complete setup of alembic to manage migrations
jaanbaaz Dec 4, 2024
4ade940
Added models, migrations, and database interactions
jaanbaaz Dec 6, 2024
eb21097
added migration files
jaanbaaz Dec 9, 2024
89d70bf
Model and migration changes
jaanbaaz Dec 22, 2024
d393d52
Merge pull request #1 from Code4GovTech/dev
jaanbaaz Dec 22, 2024
bc63a9a
Model and migration changes
jaanbaaz Dec 22, 2024
77cb56d
Merge pull request #2 from Code4GovTech/dev
jaanbaaz Dec 22, 2024
4cbeec2
dmp api changes and model changes
jaanbaaz Dec 23, 2024
85b93ba
Merge pull request #3 from Code4GovTech/dev
jaanbaaz Dec 23, 2024
2d77a75
dmp api type casting
jaanbaaz Dec 23, 2024
8ca6de8
Merge pull request #4 from Code4GovTech/dev
jaanbaaz Dec 23, 2024
a738043
Relative paths for models
jaanbaaz Dec 24, 2024
8bef9ed
Merge pull request #5 from Code4GovTech/dev
jaanbaaz Dec 24, 2024
3cbb82d
Shared Models and Queries Integrated
shreyash-work-fl Dec 24, 2024
741896b
discord bot renamed
jaanbaaz Dec 24, 2024
16aa221
Merge pull request #6 from Code4GovTech/dev
jaanbaaz Dec 24, 2024
61a5f44
Limited submodule repo as a directory
shreyash-work-fl Dec 27, 2024
34f439e
Removed Comments
shreyash-work-fl Dec 27, 2024
459ce53
replicating shared migrations directory
shreyash-work-fl Dec 27, 2024
3dafade
replicating shared migrations directory
shreyash-work-fl Dec 27, 2024
1abd19d
Added repo as dir
shreyash-work-fl Dec 27, 2024
9fc6454
renamed dir
shreyash-work-fl Dec 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files should be ignored.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/discord-bot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries


class BadgeModal(discord.ui.Modal, title="Your Badges"):
Expand All @@ -17,7 +17,7 @@ async def on_timeout(self, interaction):

class BadgeContents:
def __init__(self, name) -> None:
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
apprentinceDesc = f"""Welcome *{name}*!!


Expand Down
4 changes: 2 additions & 2 deletions cogs/discordDataScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from discord.channel import TextChannel
from discord.ext import commands, tasks

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

with open("config.json") as config_file:
config_data = json.load(config_file)
Expand All @@ -24,7 +24,7 @@
class DiscordDataScaper(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

@commands.Cog.listener()
async def on_message(self, message):
Expand Down
5 changes: 3 additions & 2 deletions cogs/listeners/member_events_cog.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient
# from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries


class MemberEventsListener(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__()

@commands.Cog.listener("on_member_join")
Expand Down
5 changes: 3 additions & 2 deletions cogs/listeners/message_events_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from discord.ext import commands

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient
# from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

serverConfig = ServerConfig()
postgresClient = PostgresClient()
postgresClient = DiscordBotQueries()


async def grantVerifiedRole(member: discord.Member):
Expand Down
5 changes: 3 additions & 2 deletions cogs/listeners/role_events_cog.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient
# from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries


class RoleEventsListener(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__()

@commands.Cog.listener()
Expand Down
4 changes: 2 additions & 2 deletions cogs/serverManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from discord.ext import commands, tasks

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

serverConfig = ServerConfig()


class ServerManagement(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

def validUser(self, ctx):
authorised_users = [
Expand Down
4 changes: 2 additions & 2 deletions cogs/userInteractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from discord.ext import commands, tasks
from dotenv import find_dotenv, load_dotenv

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

load_dotenv(find_dotenv())

Expand All @@ -16,7 +16,7 @@ class UserHandler(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.update_contributors.start()
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

@tasks.loop(minutes=60)
async def update_contributors(self):
Expand Down
6 changes: 3 additions & 3 deletions cogs/vcCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from discord.ext import commands

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

"""
with io.BytesIO(image_bytes) as image_file:
Expand All @@ -21,7 +21,7 @@
class CommunityVCView(ui.View):
def __init__(self, *, timeout=None):
super().__init__(timeout=timeout)
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

def isCommunityContributor(self, roles: list[Role]):
CommunityContributorRoleID = ServerConfig.Roles.CONTRIBUTOR_ROLE
Expand Down Expand Up @@ -215,7 +215,7 @@ async def serveCertificateLink(self, interaction: Interaction, button: ui.Button

class VCProgramSelection(ui.View):
def __init__(self, *, timeout=None):
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__(timeout=timeout)

async def resetSelectMenu(self, interaction):
Expand Down
3 changes: 2 additions & 1 deletion helpers/supabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from dotenv import load_dotenv
from sqlalchemy import create_engine,select,desc,update,delete
from sqlalchemy.orm import sessionmaker
from models import *
# from models import *
from shared_migrations.db.models import *
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession

Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from discord.ext import commands

from cogs.vcCog import VCProgramSelection
from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries
from dotenv import load_dotenv, find_dotenv


Expand Down Expand Up @@ -70,7 +70,7 @@ async def on_submit(self, interaction: discord.Interaction):
except Exception as e:
print('exception e ', e)
try:
response = await PostgresClient().updateContributor(user_data)
response = await DiscordBotQueries().updateContributor(user_data)
print("DB updated for user:", user_data["discord_id"])
except Exception as e:
print("Failed to update credentials for user: "+e)
Expand All @@ -96,7 +96,7 @@ async def hasIntroduced():
while not authentication:
print("Not authenticated. Waiting")
await asyncio.sleep(15)
authentication = await PostgresClient().read("contributors_registration", "discord_id", user.id)
authentication = await DiscordBotQueries().read("contributors_registration", "discord_id", user.id)
print("User has authenticated")
return True

Expand Down
1 change: 1 addition & 0 deletions shared_migrations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
5 changes: 5 additions & 0 deletions shared_migrations/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.analysis.extraPaths": [
"./db"
]
}
Binary file added shared_migrations/README.md
Binary file not shown.
118 changes: 118 additions & 0 deletions shared_migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
# Use forward slashes (/) also on windows to provide an os agnostic path
script_location = migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = %(DATABASE_URL)s



[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
Loading