forked from teaxyz/chai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8643509
commit 6749d61
Showing
21 changed files
with
136 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# wait for db to be ready | ||
set -uo pipefail | ||
|
||
# This script sets up the database, runs migrations, and loads initial values | ||
|
||
# Wait for database to be ready | ||
until pg_isready -h db -p 5432 -U postgres; do | ||
echo "waiting for database..." | ||
sleep 2 | ||
done | ||
|
||
# create db if needed | ||
# if [ "$( psql -XtAc "SELECT 1 FROM pg_database WHERE datname='chai'" 2&>/dev/null)" = '1' ] | ||
# Check if the 'chai' database exists, create it if it doesn't | ||
if [ "$( psql -XtAc "SELECT 1 FROM pg_database WHERE datname='chai'" -h db -U postgres)" = '1' ] | ||
then | ||
echo "Database 'chai' already exists" | ||
else | ||
echo "Database 'chai' does not exist, creating..." | ||
# Run the initialization script to create the database | ||
psql -U postgres -h db -f init-script.sql -a | ||
fi | ||
|
||
# migrate | ||
echo "db currently at $(alembic current)" | ||
# Run database migrations | ||
echo "Current database version: $(alembic current)" | ||
if alembic upgrade head | ||
then | ||
echo "migrations run successfully" | ||
echo "Migrations completed successfully" | ||
else | ||
echo "migrations failed" | ||
echo "Migration failed" | ||
exit 1 | ||
fi | ||
|
||
# load values | ||
# Load initial values into the database | ||
echo "Loading initial values into the database..." | ||
psql -U postgres -h db -d chai -f load-values.sql -a | ||
|
||
echo "Database setup and initialization complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Core Tools for CHAI Python Loaders | ||
|
||
This directory contains a set of core tools and utilities to facilitate loading the CHAI | ||
database with packaage manager data, using python helpers. These tools provide a common | ||
foundation for fetching, transforming, and loading data from various package managers | ||
into the database. | ||
|
||
## Key Components | ||
|
||
### 1. [Config](config.py) | ||
|
||
The Config module provides configuration management for loaders. It includes: | ||
|
||
- `PackageManager` enum for supported package managers | ||
- `Config` class for storing loader-specific configurations | ||
- Functions for initializing configurations and loading various types (URL types, | ||
user types, package manager IDs, dependency types) | ||
|
||
### 2. [Database](db.py) | ||
|
||
The DB class offers a set of methods for interacting with the database, including: | ||
|
||
- Inserting and selecting data for packages, versions, users, dependencies, and more | ||
- Caching mechanisms to improve performance | ||
- Batch processing capabilities for efficient data insertion | ||
|
||
### 3. [Fetcher](fetcher.py) | ||
|
||
The Fetcher class provides functionality for downloading and extracting data from | ||
package manager sources. It supports: | ||
|
||
- Downloading tarball files | ||
- Extracting contents to a specified directory | ||
|
||
### 4. [Logger](logger.py) | ||
|
||
A custom logging utility that provides consistent logging across all loaders. | ||
|
||
### 5. [Models](models/**init**.py) | ||
|
||
SQLAlchemy models representing the database schema, including: | ||
|
||
- Package, Version, User, License, DependsOn, and other relevant tables | ||
|
||
> [!NOTE] | ||
> | ||
> This is currently used to actually generate the migrations as well | ||
### 6. [Scheduler](scheduler.py) | ||
|
||
A scheduling utility that allows loaders to run at specified intervals. | ||
|
||
### 7. [Transformer](transformer.py) | ||
|
||
The Transformer class provides a base for creating package manager-specific transformers. | ||
It includes: | ||
|
||
- Methods for locating and reading input files | ||
- Placeholder methods for transforming data into the required format | ||
|
||
## Usage | ||
|
||
To create a new loader for a package manager: | ||
|
||
1. Create a new directory under `package_managers/` for your package manager. | ||
1. Implement a fetcher that inherits from the base Fetcher, that is able to fetch | ||
the raw data from the package manager's source. | ||
1. Implement a custom Transformer class that inherits from the base Transformer, that | ||
figures out how to map the raw data provided by the package managers into the data | ||
model described in the [models](models/**init**.py) module. | ||
1. Create a main script that utilizes the core components (Config, DB, Fetcher, | ||
Transformer, Scheduler) to fetch, transform, and load data. | ||
|
||
Example usage can be found in the [crates](../package_managers/crates) loader. | ||
|
||
## Contributing | ||
|
||
When adding new functionality or modifying existing core components, please ensure that | ||
changes are compatible with all existing loaders and follow the established patterns | ||
and conventions. | ||
|
||
For more detailed information on each component, refer to the individual files and their | ||
docstrings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from typing import Any | ||
|
||
from requests import get | ||
|
||
from core.logger import Logger | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters