Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions ceres/src/lfs/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ async fn lfs_add_lock(

async fn lfs_get_meta(
storage: Arc<LfsStorage>,
oid: &String,
oid: &str,
) -> Result<MetaObject, GitLFSError> {
let result = storage.get_lfs_object(oid.clone()).await.unwrap();
let result = storage.get_lfs_object(oid.to_owned()).await.unwrap();

match result {
Some(val) => Ok(MetaObject {
Expand Down
2 changes: 1 addition & 1 deletion docker/mono-pg-dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ EXPOSE 5432

# Add the database initialization script to the container
# When the container starts, PostgreSQL will automatically execute all .sql files in the docker-entrypoint-initdb.d/ directory
COPY ./sql/postgres/pg_20240205__init.sql /docker-entrypoint-initdb.d/
COPY ./sql/postgres/pg_20240905__init.sql /docker-entrypoint-initdb.d/

CMD ["postgres"]
11 changes: 0 additions & 11 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,6 @@ erDiagram

## 3. Prerequisites

- You need to execute SQL files in a specific order to init the database.

For example using `PostgreSQL`, execute the files under `sql\postgres`:

pg_20240205__init.sql

or if you are using `Mysql`, execute the files under `sql\mysql`:

mysql_20231106__init.sql



- Generating entities:
Entities can be generated from the database table structure with the following command
Expand Down
6 changes: 3 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

```bash
$ cd mega/sql/postgres
$ psql mega < pg_20240205_init.sql
$ psql mega < pg_YYYYMMDD_init.sql
```

3. Create user and grant privileges.
Expand Down Expand Up @@ -142,7 +142,7 @@

```bash
$ cd mega/sql/postgres
$ sudo -u postgres psql mega < pg_20240205__init.sql
$ sudo -u postgres psql mega < pg_YYYYMMDD__init.sql
```

4.Create user and grant privileges.
Expand Down Expand Up @@ -204,7 +204,7 @@ When the codespace is ready, the PostgreSQL will be installed and started automa
/etc/init.d/postgresql start

sudo -u postgres psql mega -c "CREATE DATABASE mega;"
sudo -u postgres psql mega < /workspaces/mega/sql/pg_20240205__init.sql
sudo -u postgres psql mega < /workspaces/mega/sql/pg_YYYYMMDD__init.sql
sudo -u postgres psql mega -c "CREATE USER mega WITH ENCRYPTED PASSWORD 'mega';"
sudo -u postgres psql mega -c "GRANT ALL PRIVILEGES ON DATABASE mega TO mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
Expand Down
2 changes: 1 addition & 1 deletion jupiter/src/storage/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn setup_sql(conn: &DatabaseConnection) -> Result<(), TransactionError<DbE
let backend = txn.get_database_backend();

// `include_str!` will expand the file while compiling, so `.sql` is not needed after that
const SETUP_SQL: &str = include_str!("../../../sql/sqlite/sqlite_20240711_init.sql");
const SETUP_SQL: &str = include_str!("../../../sql/sqlite/sqlite_20240905_init.sql");
txn.execute(Statement::from_string(backend, SETUP_SQL)).await?;
Ok(())
})
Expand Down
57 changes: 57 additions & 0 deletions sql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SQL File Update Guide

Whenever making any updates to the SQL content in the project, **make sure to also update** both the `pg_YYYYMMDD__init.sql`, `sqlite_YYYYMMDD__init.sql` files, and the **Dockerfile**. These files are used to initialize the database for PostgreSQL and SQLite respectively, ensuring that SQL changes are properly applied across different environments. Failing to update these files may lead to database inconsistencies, disrupting the system’s operation.

## Filename Date Convention

The middle part of the filename (`YYYYMMDD`, e.g., `20240205` in `pg_20240205__init.sql`) represents the **date of the last modification**. When updating these SQL files, you must update this date to the **current modification date**. This ensures that the file accurately reflects when the last changes were made, aiding in version control and troubleshooting.

For example, if you make modifications on September 5, 2024, the filenames should be updated to:
- `pg_20240905__init.sql`
- `sqlite_20240905__init.sql`

## Dockerfile Update

Mega's Docker setup relies on these SQL files for initializing the database, you **must also update the `Dockerfile`** to ensure the new SQL initialization files are copied and applied correctly. Make sure the Docker build includes the latest `pg_YYYYMMDD__init.sql` and `sqlite_YYYYMMDD__init.sql` filenames and paths, reflecting the current modification date.

For example, update the `Dockerfile` to reference the newly updated filenames:

```Dockerfile
# PostgreSQL initialization
COPY pg_20240905__init.sql /docker-entrypoint-initdb.d/

# SQLite initialization
COPY sqlite_20240905__init.sql /app/sqlite/
```

## Update Process

1. **Modify SQL Statements**
When modifying the database structure (such as tables, indexes, constraints, etc.) or data, first make the changes in the corresponding SQL file in the project.

2. **Sync Changes to `pg_YYYYMMDD__init.sql`, `sqlite_YYYYMMDD__init.sql`, and the Dockerfile**
Apply the SQL changes to both initialization files:
- `pg_YYYYMMDD__init.sql` for PostgreSQL
- `sqlite_YYYYMMDD__init.sql` for SQLite

Update the `YYYYMMDD` part of the filename to reflect the current date of modification. Additionally, ensure that the `Dockerfile` is updated to reference the new SQL files.

3. **Test Database Migration**
Ensure the updated SQL files and the new `Dockerfile` are applied in the development and test environments. Verify that the database changes are successful for both PostgreSQL and SQLite.

4. **Commit and Update Documentation**
When committing your code, ensure the updates to both `pg_YYYYMMDD__init.sql`, `sqlite_YYYYMMDD__init.sql`, and the `Dockerfile` are included, with the correct date in the filenames, and document the related database changes in the project’s change log.

## Example

For instance, if you add a new table to the project:

```sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE
);
```

You need to add this SQL to both the `pg_YYYYMMDD__init.sql` and `sqlite_YYYYMMDD__init.sql` files, adapting the SQL syntax as needed for each database system. If the modification is made on September 5, 2024, the filenames should be updated to `pg_20240905__init.sql` and `sqlite_20240905__init.sql`. Update the `Dockerfile` to reference these new filenames for PostgreSQL and SQLite initialization.
File renamed without changes.
Loading