hockey-blast-common-lib 0.1.17__tar.gz → 0.1.19__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.
Files changed (26) hide show
  1. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/PKG-INFO +1 -1
  2. hockey_blast_common_lib-0.1.19/hockey_blast_common_lib/db_connection.py +42 -0
  3. hockey_blast_common_lib-0.1.19/hockey_blast_common_lib/restore_sample_db.sh +37 -0
  4. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib.egg-info/PKG-INFO +1 -1
  5. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/setup.py +1 -1
  6. hockey_blast_common_lib-0.1.17/hockey_blast_common_lib/db_connection.py +0 -43
  7. hockey_blast_common_lib-0.1.17/hockey_blast_common_lib/restore_sample_db.sh +0 -34
  8. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/MANIFEST.in +0 -0
  9. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/README.md +0 -0
  10. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/__init__.py +0 -0
  11. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/aggregate_goalie_stats.py +0 -0
  12. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/aggregate_human_stats.py +0 -0
  13. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/aggregate_referee_stats.py +0 -0
  14. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/aggregate_skater_stats.py +0 -0
  15. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/dump_sample_db.sh +0 -0
  16. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz +0 -0
  17. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/models.py +0 -0
  18. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/options.py +0 -0
  19. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/stats_models.py +0 -0
  20. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/utils.py +0 -0
  21. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib/wsgi.py +0 -0
  22. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib.egg-info/SOURCES.txt +0 -0
  23. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib.egg-info/dependency_links.txt +0 -0
  24. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib.egg-info/requires.txt +0 -0
  25. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/hockey_blast_common_lib.egg-info/top_level.txt +0 -0
  26. {hockey_blast_common_lib-0.1.17 → hockey_blast_common_lib-0.1.19}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hockey-blast-common-lib
3
- Version: 0.1.17
3
+ Version: 0.1.19
4
4
  Summary: Common library for shared functionality and DB models
5
5
  Author: Pavel Kletskov
6
6
  Author-email: kletskov@gmail.com
@@ -0,0 +1,42 @@
1
+ import os
2
+ from sqlalchemy import create_engine
3
+ from sqlalchemy.orm import sessionmaker
4
+
5
+ # Database connection parameters per organization
6
+ DB_PARAMS = {
7
+ "frontend": {
8
+ "dbname": os.getenv("DB_NAME", "hockey_blast"),
9
+ "user": os.getenv("DB_USER", "frontend_user"),
10
+ "password": os.getenv("DB_PASSWORD", "hockey-blast"),
11
+ "host": os.getenv("DB_HOST", "localhost"),
12
+ "port": int(os.getenv("DB_PORT", 5432))
13
+ },
14
+
15
+ "frontend-sample-db": {
16
+ "dbname": os.getenv("DB_NAME_SAMPLE", "hockey_blast_sample"),
17
+ "user": os.getenv("DB_USER_SAMPLE", "frontend_user"),
18
+ "password": os.getenv("DB_PASSWORD_SAMPLE", "hockey-blast"),
19
+ "host": os.getenv("DB_HOST_SAMPLE", "localhost"),
20
+ "port": int(os.getenv("DB_PORT_SAMPLE", 5432))
21
+ },
22
+
23
+ "boss": {
24
+ "dbname": os.getenv("DB_NAME_BOSS", "hockey_blast"),
25
+ "user": os.getenv("DB_USER_BOSS", "boss"),
26
+ "password": os.getenv("DB_PASSWORD_BOSS", "WrongPassword"),
27
+ "host": os.getenv("DB_HOST_BOSS", "localhost"),
28
+ "port": int(os.getenv("DB_PORT_BOSS", 5432))
29
+ },
30
+ }
31
+
32
+ def get_db_params(config_name):
33
+ if config_name not in DB_PARAMS:
34
+ raise ValueError(f"Invalid organization: {config_name}")
35
+ return DB_PARAMS[config_name]
36
+
37
+ def create_session(config_name):
38
+ db_params = get_db_params(config_name)
39
+ db_url = f"postgresql://{db_params['user']}:{db_params['password']}@{db_params['host']}:{db_params['port']}/{db_params['dbname']}"
40
+ engine = create_engine(db_url)
41
+ Session = sessionmaker(bind=engine)
42
+ return Session()
@@ -0,0 +1,37 @@
1
+ #!/bin/zsh
2
+
3
+ # Database credentials from environment variables
4
+ DB_USER=${DB_USER:-"frontend_user"}
5
+ DB_PASSWORD=${DB_PASSWORD:-"hockey-blast"}
6
+ DB_NAME=${DB_NAME:-"hockey_blast_sample"}
7
+ DB_HOST=${DB_HOST:-"localhost"}
8
+ DB_PORT=${DB_PORT:-"5432"}
9
+ COMPRESSED_DUMP_FILE="hockey_blast_sample_backup.sql.gz"
10
+
11
+ # Superuser credentials
12
+ SUPERUSER="your_superuser"
13
+ SUPERUSER_PASSWORD="your_superuser_password"
14
+
15
+ # Export PGPASSWORD to avoid password prompt
16
+ export PGPASSWORD=$SUPERUSER_PASSWORD
17
+
18
+ # Drop the existing database if it exists
19
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$DB_NAME' AND pid <> pg_backend_pid();"
20
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="DROP DATABASE IF EXISTS $DB_NAME"
21
+
22
+ # Create a new database
23
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="CREATE DATABASE $DB_NAME OWNER $SUPERUSER"
24
+
25
+ # Export PGPASSWORD for frontend_user user
26
+ export PGPASSWORD=$DB_PASSWORD
27
+
28
+ # Restore the database from the dump file with --no-owner option
29
+ gunzip -c $COMPRESSED_DUMP_FILE | pg_restore --username=$DB_USER --host=$DB_HOST --port=$DB_PORT --dbname=$DB_NAME --format=custom --no-owner
30
+
31
+ # Create the frontend_user if it does not exist
32
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --dbname=$DB_NAME --command="DO \$\$ BEGIN IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'frontend_user') THEN CREATE ROLE frontend_user LOGIN PASSWORD '$DB_PASSWORD'; END IF; END \$\$;"
33
+
34
+ # Grant necessary permissions to the user
35
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --dbname=$DB_NAME --command="GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO frontend_user"
36
+
37
+ echo "Database restore completed: $DB_NAME"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hockey-blast-common-lib
3
- Version: 0.1.17
3
+ Version: 0.1.19
4
4
  Summary: Common library for shared functionality and DB models
5
5
  Author: Pavel Kletskov
6
6
  Author-email: kletskov@gmail.com
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='hockey-blast-common-lib', # The name of your package
5
- version='0.1.17',
5
+ version='0.1.19',
6
6
  description='Common library for shared functionality and DB models',
7
7
  author='Pavel Kletskov',
8
8
  author_email='kletskov@gmail.com',
@@ -1,43 +0,0 @@
1
- # import psycopg2
2
- from sqlalchemy import create_engine
3
- from sqlalchemy.orm import sessionmaker
4
-
5
- # Database connection parameters per organization
6
- DB_PARAMS = {
7
- "frontend": {
8
- "dbname": "hockey_blast",
9
- "user": "frontend_user",
10
- "password": "hockey-blast",
11
- "host": "localhost",
12
- "port": 5432
13
- },
14
-
15
- "frontend-sample-db": {
16
- "dbname": "hockey_blast_sample",
17
- "user": "frontend_user",
18
- "password": "hockey-blast",
19
- "host": "localhost",
20
- "port": 5432
21
- },
22
-
23
- "boss": {
24
- "dbname": "hockey_blast",
25
- "user": "boss",
26
- "password": "WrongPassword",
27
- "host": "localhost",
28
- "port": 5432
29
- },
30
-
31
- }
32
-
33
- def get_db_params(config_name):
34
- if config_name not in DB_PARAMS:
35
- raise ValueError(f"Invalid organization: {config_name}")
36
- return DB_PARAMS[config_name]
37
-
38
- def create_session(config_name):
39
- db_params = get_db_params(config_name)
40
- db_url = f"postgresql://{db_params['user']}:{db_params['password']}@{db_params['host']}:{db_params['port']}/{db_params['dbname']}"
41
- engine = create_engine(db_url)
42
- Session = sessionmaker(bind=engine)
43
- return Session()
@@ -1,34 +0,0 @@
1
- #!/bin/zsh
2
-
3
- # Database credentials from environment variables
4
- DB_USER=${DB_USER:-"frontend_user"}
5
- DB_PASSWORD=${DB_PASSWORD:-"hockey-blast"}
6
- DB_NAME=${DB_NAME:-"hockey_blast_sample"}
7
- DB_HOST=${DB_HOST:-"localhost"}
8
- DB_PORT=${DB_PORT:-"5432"}
9
- COMPRESSED_DUMP_FILE="hockey_blast_sample_backup.sql.gz"
10
-
11
- # Superuser credentials
12
- SUPERUSER="your_superuser"
13
- SUPERUSER_PASSWORD="your_superuser_password"
14
-
15
- # Export PGPASSWORD to avoid password prompt
16
- export PGPASSWORD=$SUPERUSER_PASSWORD
17
-
18
- # Drop the existing database if it exists
19
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --command="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$DB_NAME' AND pid <> pg_backend_pid();"
20
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --command="DROP DATABASE IF EXISTS $DB_NAME"
21
-
22
- # Create a new database
23
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --command="CREATE DATABASE $DB_NAME OWNER $SUPERUSER"
24
-
25
- # Export PGPASSWORD for read-only user
26
- export PGPASSWORD=$DB_PASSWORD
27
-
28
- # Restore the database from the dump file with --no-owner option
29
- gunzip -c $COMPRESSED_DUMP_FILE | pg_restore --username=$DB_USER --host=$DB_HOST --port=$DB_PORT --dbname=$DB_NAME --format=custom --no-owner
30
-
31
- # Grant necessary permissions to the read-only user
32
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT --dbname=$DB_NAME --command="GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO frontend_user"
33
-
34
- echo "Database restore completed: $DB_NAME"