diff --git a/docs/financial_docs/Database_Schema.md b/docs/financial_docs/Database_Schema.md index b732e27..1cd4449 100644 --- a/docs/financial_docs/Database_Schema.md +++ b/docs/financial_docs/Database_Schema.md @@ -72,4 +72,128 @@ This schema is designed with compatibility in mind. The transition from SQLite3 ### Conclusion -This guide provides a blueprint for a database schema capable of supporting comprehensive forex data analysis and machine learning workloads, from initial development with SQLite3 to a scalable, production-ready setup with TimescaleDB. By focusing on flexibility, scalability, and compatibility, this schema ensures that your database can grow and evolve alongside your analytical capabilities, providing a solid foundation for extracting insights from forex market data. \ No newline at end of file +This guide provides a blueprint for a database schema capable of supporting comprehensive forex data analysis and machine learning workloads, from initial development with SQLite3 to a scalable, production-ready setup with TimescaleDB. By focusing on flexibility, scalability, and compatibility, this schema ensures that your database can grow and evolve alongside your analytical capabilities, providing a solid foundation for extracting insights from forex market data. + +--- + +Setting up databases on Linux and macOS involves using the command line interface (CLI) for both SQLite3 and PostgreSQL. Here's a direct guide to get you started with creating, attaching to, verifying, and exiting databases in both environments. + +### SQLite3 Setup + +SQLite3 is often pre-installed on macOS and Linux. If it's not, you can install it via the package manager. + +#### Installation (if needed) + +- **macOS**: Use Homebrew to install SQLite3. + ```bash + brew install sqlite + ``` +- **Linux** (Debian-based systems): + ```bash + sudo apt-get update + sudo apt-get install sqlite3 + ``` + +#### Basic Commands + +- **Create or Open Database**: + ```bash + sqlite3 forex_data.db + ``` + This command creates the `forex_data.db` file if it doesn't exist or opens it if it does. + +- **Attach to Another Database** (if you're already in an SQLite session and want to work with another database simultaneously): + ```sql + ATTACH DATABASE 'path/to/other_database.db' AS other_db; + ``` + +- **Verification**: + - To verify the tables in your database: + ```sql + .tables + ``` + - To check the schema of a specific table: + ```sql + .schema forex_data + ``` + +- **Exit**: + ```sql + .quit + ``` + +### PostgreSQL (Includes TimescaleDB) Setup + +PostgreSQL needs to be installed, and TimescaleDB is an extension that you add to PostgreSQL. TimescaleDB harnesses the power of PostgreSQL for time-series data. + +#### Installation + +- **PostgreSQL**: + - **macOS**: Using Homebrew: + ```bash + brew install postgresql + ``` + - **Linux** (Debian-based systems): + ```bash + sudo apt-get update + sudo apt-get install postgresql postgresql-contrib + ``` + +- **TimescaleDB**: After installing PostgreSQL, install TimescaleDB. Check [TimescaleDB's documentation](https://docs.timescale.com/timescaledb/latest/how-to-guides/install-timescaledb/) for the most current instructions, as the installation process may vary depending on your PostgreSQL version. + +#### Basic Commands + +- **Start PostgreSQL Service**: + - **macOS**: + ```bash + brew services start postgresql + ``` + - **Linux**: + ```bash + sudo service postgresql start + ``` + +- **Create Database**: + ```bash + createdb forex_data + ``` + +- **Connect to Database**: + ```bash + psql forex_data + ``` + This command connects you to the `forex_data` database using the `psql` command-line interface. + +- **Attach to Another Database**: In PostgreSQL, you connect to databases one at a time. To switch databases: + ```sql + \c other_database_name + ``` + +- **Verification**: + - List all tables: + ```sql + \dt + ``` + - Check the schema of a specific table: + ```sql + \d+ forex_data + ``` + +- **Exit**: + ```sql + \q + ``` + +### TimescaleDB Setup + +After installing TimescaleDB, you can create a hypertable from your existing table to leverage TimescaleDB's features: + +```sql +SELECT create_hypertable('forex_data', 'timestamp'); +``` + +Run this command in the `psql` interface after connecting to your database. + +This guide provides a streamlined path to setting up SQLite3 and PostgreSQL (with TimescaleDB) databases on Linux and macOS, along with basic commands for database management and schema verification. These steps will help you create a robust environment for forex data analysis and development. + +--- \ No newline at end of file