Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerized backend, model update #54

Merged
merged 14 commits into from
Nov 2, 2023
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
8 changes: 5 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# environement details
ENV=dev
DISTRIBUTION=selfhosted

POSTGRES_USER: my_user
POSTGRES_PASSWORD: my_password
POSTGRES_DB: panora_db
POSTGRES_USER=my_user
POSTGRES_PASSWORD=my_password
POSTGRES_DB=panora_db
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# **Panora**
![Group 1_updated](https://github.com/panoratech/Panora/assets/39710677/c9a35848-7b48-43af-bd6c-6a5257e19bea)


<div style="text-align:center">
<img src="https://snyk.io/test/github/panoratech/Panora/badge.svg" alt="Known Vulnerabilities">
</div>


Our product makes it quick and easy for SaaS teams to ship customer-facing integrations between their product and others.

We do so by providing a single API that abstracts similar tools your customer may use along your product behind a common data model.
Expand Down
13 changes: 6 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: panora
version: '3.8'

services:

postgres:
image: postgres:14.6
environment:
Expand All @@ -11,19 +13,16 @@ services:
- "5432:5432"
volumes:
- ./pg_data:/var/lib/postgresql/data
networks:
- my_network
- ./packages/api/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql

api:
build: ./packages/api
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@host.docker.internal:5432/${POSTGRES_DB}?ssl=false
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?ssl=false
DISTRIBUTION: ${DISTRIBUTION}
restart:
unless-stopped
ports:
- 3000:3000
depends_on:
- postgres

networks:
my_network:
driver: bridge
21 changes: 12 additions & 9 deletions packages/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ RUN corepack enable
COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
#FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --no-frozen-lockfile

FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
#FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --no-frozen-lockfile
RUN pnpm run build

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist
EXPOSE 3000
#FROM base
#COPY --from=prod-deps /app/node_modules /app/node_modules
#COPY --from=build /app/dist /app/dist
#COPY --from=build /app/prisma /app/prisma
#RUN ls /app/prisma

CMD [ "pnpm", "run start" ]
EXPOSE 3000

# Start the server using the production build
CMD [ "node", "dist/main.js" ]
23 changes: 16 additions & 7 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ model jobs {
}

model jobs_status_history {
id Int @id(map: "pk_1") @default(autoincrement())
timestamp DateTime @default(now()) @db.Timestamp(6)
previous_status String
new_status String
id_job Int @default(autoincrement())
jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4")
id_jobs_status_history Int @id(map: "pk_1") @default(autoincrement())
timestamp DateTime @default(now()) @db.Timestamp(6)
previous_status String
new_status String
id_job Int @default(autoincrement())
jobs jobs @relation(fields: [id_job], references: [id_job], onDelete: NoAction, onUpdate: NoAction, map: "fk_4")

@@index([id_job], map: "id_job_jobs_status_history")
}
Expand All @@ -63,7 +63,6 @@ model organizations {
name String
stripe_customer_id String
timezone String
logo_url String
projects projects[]
users users[]
}
Expand All @@ -86,7 +85,17 @@ model users {
created_at DateTime @default(now()) @db.Timestamp(6)
modified_at DateTime @default(now()) @db.Timestamp(6)
id_organization BigInt
api_keys api_keys[]
organizations organizations @relation(fields: [id_organization], references: [id_organization], onDelete: NoAction, onUpdate: NoAction, map: "fk_5")

@@index([id_organization], map: "fk_1_users")
}

model api_keys {
id_api_key BigInt @id(map: "id_") @default(autoincrement())
api_key String @unique(map: "unique_api_keys")
id_user Int
users users @relation(fields: [id_user], references: [id_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_7")

@@index([id_user], map: "fk_1")
}
210 changes: 210 additions & 0 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@

-- ************************************** organizations

CREATE TABLE organizations
(
id_organization bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
name text NOT NULL,
stripe_customer_id text NOT NULL,
CONSTRAINT PK_organizations PRIMARY KEY ( id_organization )
);








-- ************************************** jobs

CREATE TABLE jobs
(
id_job serial NOT NULL,
status text NOT NULL,
"timestamp" timestamp NOT NULL DEFAULT NOW(),
CONSTRAINT PK_jobs PRIMARY KEY ( id_job )
);



COMMENT ON COLUMN jobs.status IS 'pending,, retry_scheduled, failed, success';





-- ************************************** users

CREATE TABLE users
(
id_user serial NOT NULL,
email text NOT NULL,
password_hash text NOT NULL,
first_name text NOT NULL,
last_name text NOT NULL,
created_at timestamp NOT NULL DEFAULT NOW(),
modified_at timestamp NOT NULL DEFAULT NOW(),
id_organization bigint NULL,
CONSTRAINT PK_users PRIMARY KEY ( id_user ),
CONSTRAINT FK_5 FOREIGN KEY ( id_organization ) REFERENCES organizations ( id_organization )
);

CREATE INDEX FK_1_users ON users
(
id_organization
);



COMMENT ON COLUMN users.created_at IS 'DEFAULT NOW() to automatically insert a value if nothing supplied';





-- ************************************** projects

CREATE TABLE projects
(
id_project serial NOT NULL,
name text NOT NULL,
id_organization bigint NOT NULL,
CONSTRAINT PK_projects PRIMARY KEY ( id_project ),
CONSTRAINT FK_6 FOREIGN KEY ( id_organization ) REFERENCES organizations ( id_organization )
);

CREATE INDEX FK_1_projects ON projects
(
id_organization
);








-- ************************************** jobs_status_history

CREATE TABLE jobs_status_history
(
id_jobs_status_history serial NOT NULL,
"timestamp" timestamp NOT NULL DEFAULT NOW(),
previous_status text NOT NULL,
new_status text NOT NULL,
id_job serial NOT NULL,
CONSTRAINT PK_1 PRIMARY KEY ( id_jobs_status_history ),
CONSTRAINT FK_4 FOREIGN KEY ( id_job ) REFERENCES jobs ( id_job )
);

CREATE INDEX id_job_jobs_status_history ON jobs_status_history
(
id_job
);



COMMENT ON COLUMN jobs_status_history.previous_status IS 'void when first initialization';
COMMENT ON COLUMN jobs_status_history.new_status IS 'pending, retry_scheduled, failed, success';





-- ************************************** crm_contacts

CREATE TABLE crm_contacts
(
id_crm_contact serial NOT NULL,
first_name text NOT NULL,
last_name text NOT NULL,
id_job serial NOT NULL,
CONSTRAINT PK_crm_contacts PRIMARY KEY ( id_crm_contact ),
CONSTRAINT job_id_crm_contact FOREIGN KEY ( id_job ) REFERENCES jobs ( id_job )
);

CREATE INDEX crm_contact_id_job ON crm_contacts
(
id_job
);








-- ************************************** crm_contacts_phone_numbers

CREATE TABLE crm_contacts_phone_numbers
(
id_crm_contacts_phone_number serial NOT NULL,
phone_number text NOT NULL,
phone_type text NOT NULL,
id_crm_contact serial NOT NULL,
CONSTRAINT PK_crm_contacts_phone_numbers PRIMARY KEY ( id_crm_contacts_phone_number ),
CONSTRAINT FK_2 FOREIGN KEY ( id_crm_contact ) REFERENCES crm_contacts ( id_crm_contact )
);

CREATE INDEX crm_contactID_crm_contact_phone_number ON crm_contacts_phone_numbers
(
id_crm_contact
);








-- ************************************** crm_contact_email_addresses

CREATE TABLE crm_contact_email_addresses
(
id_crm_contact_email serial NOT NULL,
email_address text NOT NULL,
email_address_type text NOT NULL,
id_crm_contact serial NOT NULL,
CONSTRAINT PK_crm_contact_email_addresses PRIMARY KEY ( id_crm_contact_email ),
CONSTRAINT FK_3 FOREIGN KEY ( id_crm_contact ) REFERENCES crm_contacts ( id_crm_contact )
);

CREATE INDEX crm_contactID_crm_contact_email_address ON crm_contact_email_addresses
(
id_crm_contact
);








-- ************************************** api_keys

CREATE TABLE api_keys
(
id_api_key bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
api_key_hash text NOT NULL,
id_project int NOT NULL,
id_user int NOT NULL,
CONSTRAINT id_ PRIMARY KEY ( id_api_key ),
CONSTRAINT unique_api_keys UNIQUE ( api_key_hash ),
CONSTRAINT FK_7 FOREIGN KEY ( id_project ) REFERENCES projects ( id_project ),
CONSTRAINT FK_8 FOREIGN KEY ( id_user ) REFERENCES users ( id_user )
);

CREATE INDEX FK_1 ON api_keys
(
id_project
);

CREATE INDEX FK_2 ON api_keys
(
id_user
);
Loading