eggi-ai-db-schema-2 12.54.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +750 -0
- package/README.md +655 -0
- package/dist/config/database.d.ts +28 -0
- package/dist/config/database.d.ts.map +1 -0
- package/dist/config/database.js +72 -0
- package/dist/config/database.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/database-service.d.ts +689 -0
- package/dist/lib/database-service.d.ts.map +1 -0
- package/dist/lib/database-service.js +1362 -0
- package/dist/lib/database-service.js.map +1 -0
- package/dist/lib/db-types.d.ts +167 -0
- package/dist/lib/db-types.d.ts.map +1 -0
- package/dist/lib/db-types.js +28 -0
- package/dist/lib/db-types.js.map +1 -0
- package/dist/lib/db.d.ts +58 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/db.js +292 -0
- package/dist/lib/db.js.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +26 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/pg-client.d.ts +50 -0
- package/dist/lib/pg-client.d.ts.map +1 -0
- package/dist/lib/pg-client.js +106 -0
- package/dist/lib/pg-client.js.map +1 -0
- package/dist/lib/schema.d.ts +298 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/schema.js +12 -0
- package/dist/lib/schema.js.map +1 -0
- package/dist/migration-manager.d.ts +49 -0
- package/dist/migration-manager.d.ts.map +1 -0
- package/dist/migration-manager.js +282 -0
- package/dist/migration-manager.js.map +1 -0
- package/dist/queries/minimal-connections.d.ts +31 -0
- package/dist/queries/minimal-connections.d.ts.map +1 -0
- package/dist/queries/minimal-connections.js +143 -0
- package/dist/queries/minimal-connections.js.map +1 -0
- package/dist/schema.ts +340 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +40 -0
- package/dist/seed.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/types.d.ts +77 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/authenticated-user-operations.d.ts +110 -0
- package/dist/utils/authenticated-user-operations.d.ts.map +1 -0
- package/dist/utils/authenticated-user-operations.js +292 -0
- package/dist/utils/authenticated-user-operations.js.map +1 -0
- package/dist/utils/authentication-operations.d.ts +48 -0
- package/dist/utils/authentication-operations.d.ts.map +1 -0
- package/dist/utils/authentication-operations.js +172 -0
- package/dist/utils/authentication-operations.js.map +1 -0
- package/dist/utils/company-mapping-job-operations.d.ts +103 -0
- package/dist/utils/company-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/company-mapping-job-operations.js +413 -0
- package/dist/utils/company-mapping-job-operations.js.map +1 -0
- package/dist/utils/company-sheet-upload-operations.d.ts +53 -0
- package/dist/utils/company-sheet-upload-operations.d.ts.map +1 -0
- package/dist/utils/company-sheet-upload-operations.js +135 -0
- package/dist/utils/company-sheet-upload-operations.js.map +1 -0
- package/dist/utils/contact-operations.d.ts +70 -0
- package/dist/utils/contact-operations.d.ts.map +1 -0
- package/dist/utils/contact-operations.js +294 -0
- package/dist/utils/contact-operations.js.map +1 -0
- package/dist/utils/forager-linkedin-operations.d.ts +74 -0
- package/dist/utils/forager-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/forager-linkedin-operations.js +778 -0
- package/dist/utils/forager-linkedin-operations.js.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts +23 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.js +282 -0
- package/dist/utils/ghost-genius-linkedin-operations.js.map +1 -0
- package/dist/utils/index.d.ts +29 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +77 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/introduction-request-operations.d.ts +159 -0
- package/dist/utils/introduction-request-operations.d.ts.map +1 -0
- package/dist/utils/introduction-request-operations.js +481 -0
- package/dist/utils/introduction-request-operations.js.map +1 -0
- package/dist/utils/invitation-operations.d.ts +141 -0
- package/dist/utils/invitation-operations.d.ts.map +1 -0
- package/dist/utils/invitation-operations.js +749 -0
- package/dist/utils/invitation-operations.js.map +1 -0
- package/dist/utils/linkedin-account-operations.d.ts +45 -0
- package/dist/utils/linkedin-account-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-operations.js +279 -0
- package/dist/utils/linkedin-account-operations.js.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts +77 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.js +274 -0
- package/dist/utils/linkedin-account-relationship-operations.js.map +1 -0
- package/dist/utils/linkedin-data-operations.d.ts +102 -0
- package/dist/utils/linkedin-data-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-data-operations.js +613 -0
- package/dist/utils/linkedin-data-operations.js.map +1 -0
- package/dist/utils/linkedin-identifier-utils.d.ts +31 -0
- package/dist/utils/linkedin-identifier-utils.d.ts.map +1 -0
- package/dist/utils/linkedin-identifier-utils.js +63 -0
- package/dist/utils/linkedin-identifier-utils.js.map +1 -0
- package/dist/utils/linkedin-profile-cache.d.ts +131 -0
- package/dist/utils/linkedin-profile-cache.d.ts.map +1 -0
- package/dist/utils/linkedin-profile-cache.js +418 -0
- package/dist/utils/linkedin-profile-cache.js.map +1 -0
- package/dist/utils/llm-inference-job-operations.d.ts +116 -0
- package/dist/utils/llm-inference-job-operations.d.ts.map +1 -0
- package/dist/utils/llm-inference-job-operations.js +266 -0
- package/dist/utils/llm-inference-job-operations.js.map +1 -0
- package/dist/utils/mapping-job-operations.d.ts +272 -0
- package/dist/utils/mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/mapping-job-operations.js +833 -0
- package/dist/utils/mapping-job-operations.js.map +1 -0
- package/dist/utils/mapping-operations.d.ts +80 -0
- package/dist/utils/mapping-operations.d.ts.map +1 -0
- package/dist/utils/mapping-operations.js +318 -0
- package/dist/utils/mapping-operations.js.map +1 -0
- package/dist/utils/on-demand-mapping-operations.d.ts +199 -0
- package/dist/utils/on-demand-mapping-operations.d.ts.map +1 -0
- package/dist/utils/on-demand-mapping-operations.js +728 -0
- package/dist/utils/on-demand-mapping-operations.js.map +1 -0
- package/dist/utils/onboarding-operations.d.ts +53 -0
- package/dist/utils/onboarding-operations.d.ts.map +1 -0
- package/dist/utils/onboarding-operations.js +223 -0
- package/dist/utils/onboarding-operations.js.map +1 -0
- package/dist/utils/organization-assignment-job-operations.d.ts +258 -0
- package/dist/utils/organization-assignment-job-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-job-operations.js +881 -0
- package/dist/utils/organization-assignment-job-operations.js.map +1 -0
- package/dist/utils/organization-assignment-operations.d.ts +59 -0
- package/dist/utils/organization-assignment-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-operations.js +130 -0
- package/dist/utils/organization-assignment-operations.js.map +1 -0
- package/dist/utils/organization-operations.d.ts +275 -0
- package/dist/utils/organization-operations.d.ts.map +1 -0
- package/dist/utils/organization-operations.js +993 -0
- package/dist/utils/organization-operations.js.map +1 -0
- package/dist/utils/organization-relationship-operations.d.ts +59 -0
- package/dist/utils/organization-relationship-operations.d.ts.map +1 -0
- package/dist/utils/organization-relationship-operations.js +240 -0
- package/dist/utils/organization-relationship-operations.js.map +1 -0
- package/dist/utils/quota-operations.d.ts +107 -0
- package/dist/utils/quota-operations.d.ts.map +1 -0
- package/dist/utils/quota-operations.js +692 -0
- package/dist/utils/quota-operations.js.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts +42 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.js +169 -0
- package/dist/utils/recursive-mapping-job-operations.js.map +1 -0
- package/dist/utils/relationship-operations.d.ts +130 -0
- package/dist/utils/relationship-operations.d.ts.map +1 -0
- package/dist/utils/relationship-operations.js +329 -0
- package/dist/utils/relationship-operations.js.map +1 -0
- package/dist/utils/sales-pipeline-operations.d.ts +143 -0
- package/dist/utils/sales-pipeline-operations.d.ts.map +1 -0
- package/dist/utils/sales-pipeline-operations.js +649 -0
- package/dist/utils/sales-pipeline-operations.js.map +1 -0
- package/dist/utils/skills-operations.d.ts +117 -0
- package/dist/utils/skills-operations.d.ts.map +1 -0
- package/dist/utils/skills-operations.js +487 -0
- package/dist/utils/skills-operations.js.map +1 -0
- package/dist/utils/subscription-operations.d.ts +123 -0
- package/dist/utils/subscription-operations.d.ts.map +1 -0
- package/dist/utils/subscription-operations.js +391 -0
- package/dist/utils/subscription-operations.js.map +1 -0
- package/dist/utils/unipile-account-operations.d.ts +96 -0
- package/dist/utils/unipile-account-operations.d.ts.map +1 -0
- package/dist/utils/unipile-account-operations.js +255 -0
- package/dist/utils/unipile-account-operations.js.map +1 -0
- package/dist/utils/user-industry-operations.d.ts +80 -0
- package/dist/utils/user-industry-operations.d.ts.map +1 -0
- package/dist/utils/user-industry-operations.js +237 -0
- package/dist/utils/user-industry-operations.js.map +1 -0
- package/dist/utils/user-operations.d.ts +87 -0
- package/dist/utils/user-operations.d.ts.map +1 -0
- package/dist/utils/user-operations.js +212 -0
- package/dist/utils/user-operations.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Migration Manager
|
|
5
|
+
*
|
|
6
|
+
* This utility manages database migrations using native PostgreSQL.
|
|
7
|
+
* It creates a simple migration tracking table and provides commands to:
|
|
8
|
+
* - Initialize the migration tracking system
|
|
9
|
+
* - Apply migrations
|
|
10
|
+
* - Check migration status
|
|
11
|
+
* - Rollback migrations (if needed)
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.MigrationManager = void 0;
|
|
15
|
+
const pg_1 = require("pg");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const database_1 = require("./config/database");
|
|
19
|
+
class MigrationManager {
|
|
20
|
+
constructor(connectionString) {
|
|
21
|
+
// Parse connection string to extract SSL config
|
|
22
|
+
const url = new URL(connectionString);
|
|
23
|
+
const pgPoolConfig = {
|
|
24
|
+
host: url.hostname,
|
|
25
|
+
port: parseInt(url.port) || 5432,
|
|
26
|
+
database: url.pathname.slice(1), // Remove leading '/'
|
|
27
|
+
user: url.username,
|
|
28
|
+
password: decodeURIComponent(url.password),
|
|
29
|
+
// Handle SSL: RDS requires SSL but with rejectUnauthorized: false for self-signed certs
|
|
30
|
+
ssl: url.searchParams.get('sslmode') === 'disable'
|
|
31
|
+
? false
|
|
32
|
+
: { rejectUnauthorized: false },
|
|
33
|
+
};
|
|
34
|
+
this.db = new pg_1.Pool(pgPoolConfig);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the migration tracking system
|
|
38
|
+
*/
|
|
39
|
+
async init() {
|
|
40
|
+
console.log("🚀 Initializing migration tracking system...");
|
|
41
|
+
try {
|
|
42
|
+
// Create migrations schema if it doesn't exist
|
|
43
|
+
await this.db.query(`CREATE SCHEMA IF NOT EXISTS migrations`);
|
|
44
|
+
// Create migration tracking table
|
|
45
|
+
await this.db.query(`
|
|
46
|
+
CREATE TABLE IF NOT EXISTS migrations.applied_migrations (
|
|
47
|
+
id SERIAL PRIMARY KEY,
|
|
48
|
+
migration_name VARCHAR(255) NOT NULL UNIQUE,
|
|
49
|
+
migration_hash VARCHAR(64) NOT NULL,
|
|
50
|
+
applied_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
51
|
+
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
52
|
+
)
|
|
53
|
+
`);
|
|
54
|
+
console.log("✅ Migration tracking system initialized successfully");
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("❌ Failed to initialize migration tracking system:", error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get all migration files from the migrations directory
|
|
63
|
+
*/
|
|
64
|
+
getMigrationFiles() {
|
|
65
|
+
const migrationsDir = (0, path_1.join)(process.cwd(), "migrations");
|
|
66
|
+
const files = (0, fs_1.readdirSync)(migrationsDir)
|
|
67
|
+
.filter(file => file.endsWith(".sql"))
|
|
68
|
+
.sort();
|
|
69
|
+
return files.map(file => {
|
|
70
|
+
const match = file.match(/^(\d+)_(.+)\.sql$/);
|
|
71
|
+
if (!match) {
|
|
72
|
+
throw new Error(`Invalid migration file name: ${file}`);
|
|
73
|
+
}
|
|
74
|
+
const id = parseInt(match[1]);
|
|
75
|
+
const name = match[2]; // We know this exists because of the regex
|
|
76
|
+
const path = (0, path_1.join)(migrationsDir, file);
|
|
77
|
+
const content = (0, fs_1.readFileSync)(path, "utf-8");
|
|
78
|
+
const hash = this.calculateHash(content);
|
|
79
|
+
return { id, name, path, content, hash };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Calculate SHA-256 hash of migration content
|
|
84
|
+
*/
|
|
85
|
+
calculateHash(content) {
|
|
86
|
+
const crypto = require("crypto");
|
|
87
|
+
return crypto.createHash("sha256").update(content).digest("hex");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get applied migrations from database
|
|
91
|
+
*/
|
|
92
|
+
async getAppliedMigrations() {
|
|
93
|
+
try {
|
|
94
|
+
const result = await this.db.query(`
|
|
95
|
+
SELECT id, migration_name as name, migration_hash as hash, applied_at
|
|
96
|
+
FROM migrations.applied_migrations
|
|
97
|
+
ORDER BY id
|
|
98
|
+
`);
|
|
99
|
+
return result.rows;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// If table doesn't exist, return empty array
|
|
103
|
+
if (error instanceof Error &&
|
|
104
|
+
error.message.includes("relation") &&
|
|
105
|
+
error.message.includes("does not exist")) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check migration status
|
|
113
|
+
*/
|
|
114
|
+
async status() {
|
|
115
|
+
console.log("📊 Migration Status");
|
|
116
|
+
console.log("==================");
|
|
117
|
+
try {
|
|
118
|
+
const migrationFiles = this.getMigrationFiles();
|
|
119
|
+
const appliedMigrations = await this.getAppliedMigrations();
|
|
120
|
+
console.log(`\n📁 Found ${migrationFiles.length} migration files`);
|
|
121
|
+
console.log(`📋 Applied ${appliedMigrations.length} migrations\n`);
|
|
122
|
+
for (const file of migrationFiles) {
|
|
123
|
+
const fullMigrationName = `${file.id.toString().padStart(4, "0")}_${file.name}`;
|
|
124
|
+
const applied = appliedMigrations.find(m => m.name === fullMigrationName);
|
|
125
|
+
const status = applied ? "✅ Applied" : "⏳ Pending";
|
|
126
|
+
const date = applied ? `(${new Date(applied.applied_at).toISOString().split("T")[0]})` : "";
|
|
127
|
+
console.log(`${status} ${file.id.toString().padStart(3, "0")}_${file.name} ${date}`);
|
|
128
|
+
if (applied && applied.hash !== file.hash) {
|
|
129
|
+
console.log(` ⚠️ Hash mismatch! File: ${file.hash.substring(0, 8)}... DB: ${applied.hash.substring(0, 8)}...`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const pending = migrationFiles.filter(f => {
|
|
133
|
+
const fullMigrationName = `${f.id.toString().padStart(4, "0")}_${f.name}`;
|
|
134
|
+
return !appliedMigrations.find(m => m.name === fullMigrationName);
|
|
135
|
+
});
|
|
136
|
+
if (pending.length > 0) {
|
|
137
|
+
console.log(`\n🔄 ${pending.length} migrations pending application`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
console.log("\n🎉 All migrations are up to date!");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error("❌ Failed to check migration status:", error);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Apply pending migrations
|
|
150
|
+
*/
|
|
151
|
+
async migrate() {
|
|
152
|
+
console.log("🔄 Applying pending migrations...");
|
|
153
|
+
try {
|
|
154
|
+
const migrationFiles = this.getMigrationFiles();
|
|
155
|
+
const appliedMigrations = await this.getAppliedMigrations();
|
|
156
|
+
const pendingMigrations = migrationFiles.filter(f => {
|
|
157
|
+
const fullMigrationName = `${f.id.toString().padStart(4, "0")}_${f.name}`;
|
|
158
|
+
return !appliedMigrations.find(m => m.name === fullMigrationName);
|
|
159
|
+
});
|
|
160
|
+
if (pendingMigrations.length === 0) {
|
|
161
|
+
console.log("✅ No pending migrations to apply");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
console.log(`📋 Found ${pendingMigrations.length} pending migrations`);
|
|
165
|
+
for (const migration of pendingMigrations) {
|
|
166
|
+
console.log(`\n🔄 Applying migration ${migration.id}: ${migration.name}`);
|
|
167
|
+
try {
|
|
168
|
+
// Apply the migration
|
|
169
|
+
await this.db.query(migration.content);
|
|
170
|
+
// Record the migration
|
|
171
|
+
const fullMigrationName = `${migration.id.toString().padStart(4, "0")}_${migration.name}`;
|
|
172
|
+
await this.db.query(`
|
|
173
|
+
INSERT INTO migrations.applied_migrations (migration_name, migration_hash)
|
|
174
|
+
VALUES ($1, $2)
|
|
175
|
+
`, [fullMigrationName, migration.hash]);
|
|
176
|
+
console.log(`✅ Successfully applied migration ${migration.id}`);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
console.error(`❌ Failed to apply migration ${migration.id}:`, error);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
console.log("\n🎉 All migrations applied successfully!");
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
console.error("❌ Migration failed:", error);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Rollback the last migration (if needed)
|
|
192
|
+
*/
|
|
193
|
+
async rollback() {
|
|
194
|
+
console.log("⏪ Rolling back last migration...");
|
|
195
|
+
try {
|
|
196
|
+
const appliedMigrations = await this.getAppliedMigrations();
|
|
197
|
+
if (appliedMigrations.length === 0) {
|
|
198
|
+
console.log("✅ No migrations to rollback");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const lastMigration = appliedMigrations[appliedMigrations.length - 1];
|
|
202
|
+
if (!lastMigration) {
|
|
203
|
+
console.log("✅ No migrations to rollback");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
console.log(`🔄 Rolling back migration: ${lastMigration.name}`);
|
|
207
|
+
// Note: This is a simple implementation. In practice, you'd need
|
|
208
|
+
// to implement proper rollback logic for each migration
|
|
209
|
+
console.log("⚠️ Rollback functionality requires manual implementation");
|
|
210
|
+
console.log("⚠️ Please manually revert the changes and remove the migration record");
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
console.error("❌ Rollback failed:", error);
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Close database connection
|
|
219
|
+
*/
|
|
220
|
+
async close() {
|
|
221
|
+
await this.db.end();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.MigrationManager = MigrationManager;
|
|
225
|
+
// CLI Interface
|
|
226
|
+
async function main() {
|
|
227
|
+
const command = process.argv[2];
|
|
228
|
+
const env = process.argv[3] || "dev";
|
|
229
|
+
if (!["dev", "prod", "test"].includes(env)) {
|
|
230
|
+
console.error("❌ Invalid environment. Use 'dev', 'prod', or 'test'");
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
let manager;
|
|
234
|
+
try {
|
|
235
|
+
let connectionString;
|
|
236
|
+
// For test environment, use DATABASE_URL from environment (set by migrate.sh)
|
|
237
|
+
if (env === "test") {
|
|
238
|
+
connectionString = process.env.DATABASE_URL || "";
|
|
239
|
+
if (!connectionString) {
|
|
240
|
+
console.error("❌ DATABASE_URL environment variable is required for test environment");
|
|
241
|
+
console.error(" This should be set by the migrate.sh script");
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
connectionString = await (0, database_1.getConnectionString)(env);
|
|
247
|
+
}
|
|
248
|
+
manager = new MigrationManager(connectionString);
|
|
249
|
+
switch (command) {
|
|
250
|
+
case "init":
|
|
251
|
+
await manager.init();
|
|
252
|
+
break;
|
|
253
|
+
case "status":
|
|
254
|
+
await manager.status();
|
|
255
|
+
break;
|
|
256
|
+
case "migrate":
|
|
257
|
+
await manager.migrate();
|
|
258
|
+
break;
|
|
259
|
+
case "rollback":
|
|
260
|
+
await manager.rollback();
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
console.error("❌ Unknown command:", command);
|
|
264
|
+
console.error("Available commands: init, status, migrate, rollback");
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error("❌ Command failed:", error);
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
if (manager) {
|
|
274
|
+
await manager.close();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// Run if called directly
|
|
279
|
+
if (require.main === module) {
|
|
280
|
+
main();
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=migration-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-manager.js","sourceRoot":"","sources":["../src/migration-manager.ts"],"names":[],"mappings":";;AAEA;;;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
|
|
3
|
+
* Simple interface for Chrome extension UI
|
|
4
|
+
*/
|
|
5
|
+
export interface ChromeExtensionConnection {
|
|
6
|
+
name: string;
|
|
7
|
+
profile_image_url: string | null;
|
|
8
|
+
position: string | null;
|
|
9
|
+
current_company: string | null;
|
|
10
|
+
score: number;
|
|
11
|
+
linkedin_account_id: number;
|
|
12
|
+
linkedin_identifier: string | null;
|
|
13
|
+
linkedin_url: string | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* SIMPLE function for Chrome extension - with pagination
|
|
17
|
+
* Takes a SINGLE LinkedIn identifier and returns connections for UI
|
|
18
|
+
* Updated to work with consolidated linkedin.accounts schema
|
|
19
|
+
*/
|
|
20
|
+
export declare function getConnectionsForChromeExtension(db: Database, linkedinIdentifier: string, page?: number, pageSize?: number): Promise<{
|
|
21
|
+
results: ChromeExtensionConnection[];
|
|
22
|
+
pagination: {
|
|
23
|
+
page: number;
|
|
24
|
+
pageSize: number;
|
|
25
|
+
totalItems: number;
|
|
26
|
+
totalPages: number;
|
|
27
|
+
hasNextPage: boolean;
|
|
28
|
+
hasPreviousPage: boolean;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
//# sourceMappingURL=minimal-connections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-connections.d.ts","sourceRoot":"","sources":["../../src/queries/minimal-connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,gCAAgC,CACpD,EAAE,EAAE,QAAQ,EACZ,kBAAkB,EAAE,MAAM,EAC1B,IAAI,GAAE,MAAU,EAChB,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC;IACT,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACrC,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,OAAO,CAAC;QACrB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;CACH,CAAC,CA0ID"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConnectionsForChromeExtension = getConnectionsForChromeExtension;
|
|
4
|
+
/**
|
|
5
|
+
* SIMPLE function for Chrome extension - with pagination
|
|
6
|
+
* Takes a SINGLE LinkedIn identifier and returns connections for UI
|
|
7
|
+
* Updated to work with consolidated linkedin.accounts schema
|
|
8
|
+
*/
|
|
9
|
+
async function getConnectionsForChromeExtension(db, linkedinIdentifier, page = 1, pageSize = 10) {
|
|
10
|
+
const offset = (page - 1) * pageSize;
|
|
11
|
+
const escapedIdentifier = linkedinIdentifier.replace(/'/g, "''");
|
|
12
|
+
// Query with DISTINCT ON to get only latest relationship scores from most recent mapping job
|
|
13
|
+
// Updated to use consolidated linkedin.accounts schema
|
|
14
|
+
const query = `
|
|
15
|
+
WITH user_account AS (
|
|
16
|
+
SELECT la.id as linkedin_account_id
|
|
17
|
+
FROM linkedin.accounts la
|
|
18
|
+
WHERE la.linkedin_identifier_acoa = '${escapedIdentifier}'
|
|
19
|
+
LIMIT 1
|
|
20
|
+
),
|
|
21
|
+
latest_linkedin_relationships AS (
|
|
22
|
+
SELECT DISTINCT ON (
|
|
23
|
+
LEAST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
24
|
+
GREATEST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
25
|
+
rs.analysis_type
|
|
26
|
+
)
|
|
27
|
+
rs.linkedin_account_id_a,
|
|
28
|
+
rs.linkedin_account_id_b,
|
|
29
|
+
rs.score,
|
|
30
|
+
rs.mapping_job_id,
|
|
31
|
+
rs.created_at
|
|
32
|
+
FROM user_account ua
|
|
33
|
+
INNER JOIN linkedin.relationships rs ON ua.linkedin_account_id IN (rs.linkedin_account_id_a, rs.linkedin_account_id_b)
|
|
34
|
+
ORDER BY
|
|
35
|
+
LEAST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
36
|
+
GREATEST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
37
|
+
rs.analysis_type,
|
|
38
|
+
rs.mapping_job_id DESC,
|
|
39
|
+
rs.created_at DESC
|
|
40
|
+
),
|
|
41
|
+
user_connections AS (
|
|
42
|
+
SELECT DISTINCT
|
|
43
|
+
CASE
|
|
44
|
+
WHEN lrs.linkedin_account_id_a = ua.linkedin_account_id THEN lrs.linkedin_account_id_b
|
|
45
|
+
ELSE lrs.linkedin_account_id_a
|
|
46
|
+
END as connected_account_id,
|
|
47
|
+
lrs.score
|
|
48
|
+
FROM user_account ua
|
|
49
|
+
INNER JOIN latest_linkedin_relationships lrs ON ua.linkedin_account_id IN (lrs.linkedin_account_id_a, lrs.linkedin_account_id_b)
|
|
50
|
+
)
|
|
51
|
+
SELECT
|
|
52
|
+
COALESCE(u.given_name || ' ' || u.family_name, la.first_name || ' ' || la.last_name, 'Unknown User') as name,
|
|
53
|
+
COALESCE(la.profile_image_cloudfront_url, la.profile_picture_url) as profile_image_url,
|
|
54
|
+
la.headline as position,
|
|
55
|
+
we.company as current_company,
|
|
56
|
+
uc.score,
|
|
57
|
+
la.id as linkedin_account_id,
|
|
58
|
+
la.linkedin_identifier_acoa as linkedin_identifier,
|
|
59
|
+
CASE
|
|
60
|
+
WHEN la.public_identifier IS NOT NULL THEN
|
|
61
|
+
'https://www.linkedin.com/in/' || la.public_identifier || '/'
|
|
62
|
+
ELSE NULL
|
|
63
|
+
END as linkedin_url
|
|
64
|
+
FROM user_connections uc
|
|
65
|
+
INNER JOIN linkedin.accounts la ON uc.connected_account_id = la.id
|
|
66
|
+
LEFT JOIN users u ON la.user_id = u.id
|
|
67
|
+
LEFT JOIN LATERAL (
|
|
68
|
+
SELECT company
|
|
69
|
+
FROM linkedin.work_experience we
|
|
70
|
+
WHERE we.linkedin_account_id = la.id
|
|
71
|
+
AND we.is_current = true
|
|
72
|
+
ORDER BY we.start_date DESC NULLS LAST
|
|
73
|
+
LIMIT 1
|
|
74
|
+
) we ON true
|
|
75
|
+
ORDER BY uc.score DESC, la.id ASC
|
|
76
|
+
LIMIT ${Math.min(pageSize, 50 - offset)} OFFSET ${offset}
|
|
77
|
+
`;
|
|
78
|
+
// Get count for pagination using same logic as main query
|
|
79
|
+
const countQuery = `
|
|
80
|
+
WITH user_account AS (
|
|
81
|
+
SELECT la.id as linkedin_account_id
|
|
82
|
+
FROM linkedin.accounts la
|
|
83
|
+
WHERE la.linkedin_identifier_acoa = '${escapedIdentifier}'
|
|
84
|
+
LIMIT 1
|
|
85
|
+
),
|
|
86
|
+
latest_linkedin_relationships AS (
|
|
87
|
+
SELECT DISTINCT ON (
|
|
88
|
+
LEAST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
89
|
+
GREATEST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
90
|
+
rs.analysis_type
|
|
91
|
+
)
|
|
92
|
+
rs.linkedin_account_id_a,
|
|
93
|
+
rs.linkedin_account_id_b,
|
|
94
|
+
rs.score,
|
|
95
|
+
rs.mapping_job_id,
|
|
96
|
+
rs.created_at
|
|
97
|
+
FROM user_account ua
|
|
98
|
+
INNER JOIN linkedin.relationships rs ON ua.linkedin_account_id IN (rs.linkedin_account_id_a, rs.linkedin_account_id_b)
|
|
99
|
+
ORDER BY
|
|
100
|
+
LEAST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
101
|
+
GREATEST(rs.linkedin_account_id_a, rs.linkedin_account_id_b),
|
|
102
|
+
rs.analysis_type,
|
|
103
|
+
rs.mapping_job_id DESC,
|
|
104
|
+
rs.created_at DESC
|
|
105
|
+
),
|
|
106
|
+
user_connections AS (
|
|
107
|
+
SELECT DISTINCT
|
|
108
|
+
CASE
|
|
109
|
+
WHEN lrs.linkedin_account_id_a = ua.linkedin_account_id THEN lrs.linkedin_account_id_b
|
|
110
|
+
ELSE lrs.linkedin_account_id_a
|
|
111
|
+
END as connected_account_id
|
|
112
|
+
FROM user_account ua
|
|
113
|
+
INNER JOIN latest_linkedin_relationships lrs ON ua.linkedin_account_id IN (lrs.linkedin_account_id_a, lrs.linkedin_account_id_b)
|
|
114
|
+
)
|
|
115
|
+
SELECT COUNT(*) as total
|
|
116
|
+
FROM user_connections
|
|
117
|
+
`;
|
|
118
|
+
const [results, countResult] = await Promise.all([db.query(query), db.query(countQuery)]);
|
|
119
|
+
const actualTotal = parseInt(countResult.rows[0]?.total || "0");
|
|
120
|
+
const totalItems = Math.min(actualTotal, 50); // Cap at 50 items max
|
|
121
|
+
const totalPages = Math.ceil(totalItems / pageSize);
|
|
122
|
+
return {
|
|
123
|
+
results: results.rows.map(row => ({
|
|
124
|
+
name: row.name,
|
|
125
|
+
profile_image_url: row.profile_image_url,
|
|
126
|
+
position: row.position,
|
|
127
|
+
current_company: row.current_company,
|
|
128
|
+
score: parseFloat(row.score),
|
|
129
|
+
linkedin_account_id: parseInt(row.linkedin_account_id),
|
|
130
|
+
linkedin_identifier: row.linkedin_identifier,
|
|
131
|
+
linkedin_url: row.linkedin_url,
|
|
132
|
+
})),
|
|
133
|
+
pagination: {
|
|
134
|
+
page,
|
|
135
|
+
pageSize,
|
|
136
|
+
totalItems,
|
|
137
|
+
totalPages,
|
|
138
|
+
hasNextPage: page < totalPages,
|
|
139
|
+
hasPreviousPage: page > 1,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=minimal-connections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-connections.js","sourceRoot":"","sources":["../../src/queries/minimal-connections.ts"],"names":[],"mappings":";;AAqBA,4EAyJC;AA9JD;;;;GAIG;AACI,KAAK,UAAU,gCAAgC,CACpD,EAAY,EACZ,kBAA0B,EAC1B,OAAe,CAAC,EAChB,WAAmB,EAAE;IAYrB,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IACrC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAEjE,6FAA6F;IAC7F,uDAAuD;IACvD,MAAM,KAAK,GAAG;;;;6CAI6B,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0DlD,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,MAAM;GACzD,CAAC;IAEF,0DAA0D;IAC1D,MAAM,UAAU,GAAG;;;;6CAIwB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC7D,CAAC;IAEA,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAE1F,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE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