|
| 1 | +# How to add new storage to Postgresus (S3, FTP, Google Drive, NAS, etc.) |
| 2 | + |
| 3 | +## Backend part |
| 4 | + |
| 5 | +1. Create new model in `backend/internal/features/storages/models/{storage_name}/` folder. Implement `StorageFileSaver` interface from parent folder. |
| 6 | + - The model should implement `SaveFile(logger *slog.Logger, fileID uuid.UUID, file io.Reader) error`, `GetFile(fileID uuid.UUID) (io.ReadCloser, error)`, `DeleteFile(fileID uuid.UUID) error`, `Validate() error`, and `TestConnection() error` methods |
| 7 | + - Use UUID primary key as `StorageID` that references the main storages table |
| 8 | + - Add `TableName() string` method to return the proper table name |
| 9 | + |
| 10 | +2. Add new storage type to `backend/internal/features/storages/enums.go` in the `StorageType` constants. |
| 11 | + |
| 12 | +3. Update the main `Storage` model in `backend/internal/features/storages/model.go`: |
| 13 | + - Add new storage field with GORM foreign key relation |
| 14 | + - Update `getSpecificStorage()` method to handle the new type |
| 15 | + - Update `SaveFile()`, `GetFile()`, and `DeleteFile()` methods to route to the new storage |
| 16 | + - Update `Validate()` method to include new storage validation |
| 17 | + |
| 18 | +4. If you need to add some .env variables to test, add them in `backend/internal/config/config.go` (so we can use it in tests) |
| 19 | + |
| 20 | +5. If you need some Docker container to test, add it to `backend/docker-compose.yml.example`. For sensitive data - keep it blank. |
| 21 | + |
| 22 | +6. If you need some sensitive envs to test in pipeline, message @rostislav_dugin so I can add it to GitHub Actions. For example, Google Drive envs or FTP credentials. |
| 23 | + |
| 24 | +7. Create new migration in `backend/migrations` folder: |
| 25 | + - Create table with `storage_id` as UUID primary key |
| 26 | + - Add foreign key constraint to `storages` table with CASCADE DELETE |
| 27 | + - Look at existing storage migrations for reference |
| 28 | + |
| 29 | +8. Update tests in `backend/internal/features/storages/model_test.go` to test new storage |
| 30 | + |
| 31 | +9. Make sure that all tests are passing. |
| 32 | + |
| 33 | +## Frontend part |
| 34 | + |
| 35 | +If you are able to develop only backend - it's fine, message @rostislav_dugin so I can complete UI part. |
| 36 | + |
| 37 | +1. Add models and api to `frontend/src/entity/storages/models/` folder and update `index.ts` file to include new model exports. |
| 38 | + - Create TypeScript interface for your storage model |
| 39 | + - Add validation function if needed |
| 40 | + |
| 41 | +2. Upload an SVG icon to `public/icons/storages/`, update `src/entity/storages/models/getStorageLogoFromType.ts` to return new icon path, update `src/entity/storages/models/StorageType.ts` to include new type, and update `src/entity/storages/models/getStorageNameFromType.ts` to return new name. |
| 42 | + |
| 43 | +3. Add UI components to manage your storage: |
| 44 | + - `src/features/storages/ui/edit/storages/Edit{StorageName}Component.tsx` (for editing) |
| 45 | + - `src/features/storages/ui/show/storages/Show{StorageName}Component.tsx` (for display) |
| 46 | + |
| 47 | +4. Update main components to handle the new storage type: |
| 48 | + - `EditStorageComponent.tsx` - add import and component rendering |
| 49 | + - `ShowStorageComponent.tsx` - add import and component rendering |
| 50 | + |
| 51 | +5. Make sure everything is working as expected. |
0 commit comments