backend changes
This commit is contained in:
parent
d5d2508c58
commit
c7d0448518
@ -654,7 +654,9 @@ services:
|
||||
- GITHUB_CLIENT_ID=Ov23liQgF14aogXVZNCR
|
||||
- GITHUB_CLIENT_SECRET=8bf82a29154fdccb837bc150539a2226d00b5da5
|
||||
- GITHUB_REDIRECT_URI=http://localhost:8000/api/github/auth/github/callback
|
||||
- ATTACHED_REPOS_DIR=/home/ubuntu/git/git-repo
|
||||
- ATTACHED_REPOS_DIR=/tmp/git-repos
|
||||
- GIT_REPOS_BASE_DIR=/tmp/git-repos
|
||||
- GIT_DIFF_DIR=/tmp/git-repos/diffs
|
||||
- SESSION_SECRET=git-integration-secret-key-2024
|
||||
- JWT_ACCESS_SECRET=access-secret-key-2024-tech4biz-secure_pipeline_2024
|
||||
- API_GATEWAY_PUBLIC_URL=http://localhost:8000
|
||||
@ -677,10 +679,11 @@ services:
|
||||
# Additional environment variables for git-integration service
|
||||
- ENABLE_BACKGROUND_DIFF_PROCESSING=true
|
||||
- DIFF_PROCESSING_INTERVAL_MS=30000
|
||||
- DIFF_STORAGE_PATH=/home/ubuntu/git/git-diff
|
||||
- DIFF_STORAGE_PATH=/tmp/git-repos/diffs
|
||||
- DIFF_STORAGE_DIR=/tmp/git-repos/diffs
|
||||
- MAX_DIFF_SIZE_BYTES=10485760
|
||||
volumes:
|
||||
- /home/ubuntu/git/git-repo
|
||||
- git_repos_container_storage:/tmp/git-repos # Container-only storage using Docker volume
|
||||
networks:
|
||||
- pipeline_network
|
||||
depends_on:
|
||||
@ -853,6 +856,8 @@ volumes:
|
||||
driver: local
|
||||
migration_state:
|
||||
driver: local
|
||||
git_repos_container_storage:
|
||||
driver: local
|
||||
|
||||
# =====================================
|
||||
# Networks
|
||||
|
||||
@ -13,6 +13,12 @@ class Database {
|
||||
connectionTimeoutMillis: 2000,
|
||||
});
|
||||
|
||||
// Handle pool errors
|
||||
this.pool.on('error', (err) => {
|
||||
console.error('❌ Database pool error:', err.message);
|
||||
// Don't crash the process, just log the error
|
||||
});
|
||||
|
||||
// Test connection on startup
|
||||
this.testConnection();
|
||||
}
|
||||
|
||||
@ -306,11 +306,11 @@ router.post('/attach-repository', async (req, res) => {
|
||||
|
||||
// Store everything in PostgreSQL (without template_id)
|
||||
const insertQuery = `
|
||||
INSERT INTO github_repositories (
|
||||
INSERT INTO all_repositories (
|
||||
repository_url, repository_name, owner_name,
|
||||
branch_name, is_public, metadata, codebase_analysis, sync_status,
|
||||
requires_auth, user_id
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
requires_auth, user_id, provider_name
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
RETURNING *
|
||||
`;
|
||||
|
||||
@ -324,7 +324,8 @@ router.post('/attach-repository', async (req, res) => {
|
||||
JSON.stringify(codebaseAnalysis),
|
||||
'syncing', // Start with syncing status
|
||||
!isPublicRepo, // requires_auth is true for private repos
|
||||
userId || null
|
||||
userId || null,
|
||||
'github' // provider_name
|
||||
];
|
||||
|
||||
const insertResult = await database.query(insertQuery, insertValues);
|
||||
@ -354,7 +355,7 @@ router.post('/attach-repository', async (req, res) => {
|
||||
// Update sync status based on download result
|
||||
const finalSyncStatus = downloadResult.success ? 'synced' : 'error';
|
||||
await database.query(
|
||||
'UPDATE github_repositories SET sync_status = $1, updated_at = NOW() WHERE id = $2',
|
||||
'UPDATE all_repositories SET sync_status = $1, updated_at = NOW() WHERE id = $2',
|
||||
[finalSyncStatus, repositoryRecord.id]
|
||||
);
|
||||
|
||||
@ -650,7 +651,7 @@ router.get('/repository/:id/diff', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { from, to, path: dirPath } = req.query;
|
||||
|
||||
const repoQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const repoQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const repoResult = await database.query(repoQuery, [id]);
|
||||
if (repoResult.rows.length === 0) {
|
||||
return res.status(404).json({ success: false, message: 'Repository not found' });
|
||||
@ -673,7 +674,7 @@ router.get('/repository/:id/changes', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { since } = req.query;
|
||||
|
||||
const repoQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const repoQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const repoResult = await database.query(repoQuery, [id]);
|
||||
if (repoResult.rows.length === 0) {
|
||||
return res.status(404).json({ success: false, message: 'Repository not found' });
|
||||
@ -702,7 +703,7 @@ router.get('/template/:id/repository', async (req, res) => {
|
||||
const query = `
|
||||
SELECT gr.*, rs.local_path, rs.storage_status, rs.total_files_count,
|
||||
rs.total_directories_count, rs.total_size_bytes, rs.download_completed_at
|
||||
FROM github_repositories gr
|
||||
FROM all_repositories gr
|
||||
LEFT JOIN repository_storage rs ON gr.id = rs.repository_id
|
||||
WHERE gr.template_id = $1
|
||||
ORDER BY gr.created_at DESC
|
||||
@ -753,7 +754,7 @@ router.get('/repository/:id/structure', async (req, res) => {
|
||||
const { path: directoryPath } = req.query;
|
||||
|
||||
// Get repository info
|
||||
const repoQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const repoQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const repoResult = await database.query(repoQuery, [id]);
|
||||
|
||||
if (repoResult.rows.length === 0) {
|
||||
@ -844,7 +845,7 @@ router.get('/repository/:id/files', async (req, res) => {
|
||||
const { directory_path = '' } = req.query;
|
||||
|
||||
// Get repository info
|
||||
const repoQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const repoQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const repoResult = await database.query(repoQuery, [id]);
|
||||
|
||||
if (repoResult.rows.length === 0) {
|
||||
@ -1043,7 +1044,7 @@ router.get('/template/:id/repositories', async (req, res) => {
|
||||
const query = `
|
||||
SELECT gr.*, rs.local_path, rs.storage_status, rs.total_files_count,
|
||||
rs.total_directories_count, rs.total_size_bytes, rs.download_completed_at
|
||||
FROM github_repositories gr
|
||||
FROM all_repositories gr
|
||||
LEFT JOIN repository_storage rs ON gr.id = rs.repository_id
|
||||
WHERE gr.template_id = $1
|
||||
ORDER BY gr.created_at DESC
|
||||
@ -1117,7 +1118,7 @@ router.post('/repository/:id/sync', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
// Get repository info
|
||||
const repoQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const repoQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const repoResult = await database.query(repoQuery, [id]);
|
||||
|
||||
if (repoResult.rows.length === 0) {
|
||||
@ -1140,7 +1141,7 @@ router.post('/repository/:id/sync', async (req, res) => {
|
||||
|
||||
// Update sync status
|
||||
await database.query(
|
||||
'UPDATE github_repositories SET sync_status = $1, updated_at = NOW() WHERE id = $2',
|
||||
'UPDATE all_repositories SET sync_status = $1, updated_at = NOW() WHERE id = $2',
|
||||
[downloadResult.success ? 'synced' : 'error', id]
|
||||
);
|
||||
|
||||
@ -1165,7 +1166,7 @@ router.delete('/repository/:id', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
// Get repository info before deletion
|
||||
const getQuery = 'SELECT * FROM github_repositories WHERE id = $1';
|
||||
const getQuery = 'SELECT * FROM all_repositories WHERE id = $1';
|
||||
const getResult = await database.query(getQuery, [id]);
|
||||
|
||||
if (getResult.rows.length === 0) {
|
||||
@ -1184,7 +1185,7 @@ router.delete('/repository/:id', async (req, res) => {
|
||||
|
||||
// Delete repository record
|
||||
await database.query(
|
||||
'DELETE FROM github_repositories WHERE id = $1',
|
||||
'DELETE FROM all_repositories WHERE id = $1',
|
||||
[id]
|
||||
);
|
||||
|
||||
@ -1214,7 +1215,7 @@ router.get('/user/:user_id/repositories', async (req, res) => {
|
||||
const query = `
|
||||
SELECT gr.*, rs.local_path, rs.storage_status, rs.total_files_count,
|
||||
rs.total_directories_count, rs.total_size_bytes, rs.download_completed_at
|
||||
FROM github_repositories gr
|
||||
FROM all_repositories gr
|
||||
LEFT JOIN repository_storage rs ON gr.id = rs.repository_id
|
||||
WHERE gr.user_id = $1
|
||||
ORDER BY gr.created_at DESC
|
||||
|
||||
Loading…
Reference in New Issue
Block a user