Skip to content

Commit

Permalink
fix: aggregation & chore: upgrade dependencies (teableio#236)
Browse files Browse the repository at this point in the history
* fix: aggregation function

* fix: record sort

* chore: upgrade dependencies

* docs: update readme.md

* fix: init bootstrap provider unit error

---------

Co-authored-by: pengap <[email protected]>
  • Loading branch information
Pengap and Pengap authored Nov 1, 2023
1 parent 63dc502 commit fd6f6ca
Show file tree
Hide file tree
Showing 155 changed files with 6,765 additions and 8,489 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: 📥 Monorepo install
uses: ./.github/actions/pnpm-install

- name: 🧪 Run Tests
env:
CI: 1
run: |
make ${{ matrix.database-type }}.integration.test
- name: ⛔ Stop Database(s)
run: |
make docker.down
if: matrix.database-type != 'sqlite'
23 changes: 16 additions & 7 deletions .ncurc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
# @link https://github.com/raineorshine/npm-check-updates

# Add here exclusions on packages if any
reject: [
# execa (6.0.0 is esm and does not work with ts-jest)
'execa',
# Too early cause in esm
'is-port-reachable',
'i18next',
'react-i18next',
reject:
[
'vitest',
'@vitest/coverage-v8',
'@vitest/coverage-istanbul',
'@vitest/ui',

'vite-plugin-svgr',

'@remix-run/dev',
'@remix-run/eslint-config',
'@remix-run/node',
'@remix-run/react',
'@remix-run/serve',
'@vercel/remix',
'remix',
]
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.1
83 changes: 55 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SHELL := /usr/bin/env bash

ENV_PATH ?= apps/nextjs-app

DOCKER_COMPOSE ?= docker compose

DOCKER_COMPOSE_ENV_FILE := $(wildcard ./dockers/.env)
Expand All @@ -8,6 +10,7 @@ COMPOSE_FILE_ARGS := --env-file $(DOCKER_COMPOSE_ENV_FILE) $(foreach yml,$(COMPO

NETWORK_MODE ?= teablenet
CI_JOB_ID ?= 0
CI ?= 0

# Timeout used to await services to become healthy
TIMEOUT ?= 300
Expand All @@ -16,6 +19,10 @@ SCRATCH ?= /tmp

UNAME_S := $(shell uname -s)

# prisma database url defaults
SQLITE_PRISMA_DATABASE_URL ?= file:../../db/main.db
POSTGES_PRISMA_DATABASE_URL ?= postgresql:https://teable:[email protected]:5432/teable?schema=public

# If the first make argument is "start", "stop"...
ifeq (docker.start,$(firstword $(MAKECMDGOALS)))
SERVICE_TARGET = true
Expand Down Expand Up @@ -64,6 +71,10 @@ ifneq ($(CI_JOB_ID),)
NETWORK_MODE := teablenet-$(CI_JOB_ID)
endif

ifeq ($(CI),0)
export NODE_ENV = development
endif


ifeq ($(UNAME_S),Linux)
DOCKER_GID ?= $(shell getent group docker | cut -d: -f 3)
Expand All @@ -80,16 +91,15 @@ DOCKER_COMPOSE_ARGS := DOCKER_UID=$(shell id -u) \


define print_db_mode_options
@echo -e "\nSelect a database to start."
@echo -e "\n\tsqlite Lightweight embedded, ideal for mobile and embedded systems, simple, resource-efficient, "
@echo -e "\t\t\t\teasy integration (default database)"
@echo -e "\tpostges(pg) Powerful and scalable, suitable for complex enterprise needs, highly customizable, rich community support\n"
@echo -e "\nSelect a database to start.\n"
@echo -e "1)sqlite Lightweight embedded, ideal for mobile and embedded systems, simple, resource-efficient, easy integration (default database)"
@echo -e "2)postges(pg) Powerful and scalable, suitable for complex enterprise needs, highly customizable, rich community support\n"
endef

define print_db_push_options
@echo -e "The 'db pull' command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.\n"
@echo -e "0) sqlite"
@echo -e "1) postges(pg)\n"
@echo -e "1) sqlite"
@echo -e "2) postges(pg)\n"
endef

.PHONY: db-mode sqlite-mode postgres-mode gen-prisma-schema gen-sqlite-prisma-schema gen-postgres-prisma-schema
Expand Down Expand Up @@ -157,24 +167,23 @@ docker.status:
docker.images:
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) images

sqlite.integration.test: docker.create.network
make docker.build integration-test
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) run -T --no-deps --rm \
-e PRISMA_DATABASE_URL=file:../../db/.test/main.db \
integration-test bash -c \
'make sqlite-mode && \
pnpm g:test-e2e'
sqlite.integration.test:
@export PRISMA_DATABASE_URL='file:../../db/.test/main.db'; \
make sqlite-mode; \
pnpm -F "./packages/**" run build; \
pnpm g:test-e2e

postgres.integration.test: docker.create.network
make docker.build integration-test
docker rm -fv teable-postgres-$(CI_JOB_ID)
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) run -d -T --no-deps --rm --name teable-postgres-$(CI_JOB_ID) teable-postgres
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) run -T --no-deps --rm \
-e PRISMA_DATABASE_URL=postgresql:https://teable:teable@teable-postgres:5432/teable?schema=public \
integration-test bash -c \
'chmod +x ./scripts/wait-for-it.sh && ./scripts/wait-for-it.sh teable-postgres:5432 --timeout=30 -- \
make postgres-mode && \
pnpm g:test-e2e'
@TEST_PG_CONTAINER_NAME=teable-postgres-$(CI_JOB_ID); \
docker rm -fv $$TEST_PG_CONTAINER_NAME | true; \
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) run -p 25432:5432 -d -T --no-deps --rm --name $$TEST_PG_CONTAINER_NAME teable-postgres; \
chmod +x scripts/wait-for; \
scripts/wait-for 127.0.0.1:25432 --timeout=15 -- echo 'pg database started successfully' && \
export PRISMA_DATABASE_URL=postgresql:https://teable:[email protected]:25432/e2e_test_teable?schema=public && \
make postgres-mode && \
pnpm -F "./packages/**" run build && \
pnpm g:test-e2e && \
docker rm -fv $$TEST_PG_CONTAINER_NAME

gen-sqlite-prisma-schema:
@cd ./packages/db-main-prisma; \
Expand All @@ -199,10 +208,10 @@ postgres-db-push: ## db-push by postgres
db-push: ## connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.
$(print_db_push_options)
@read -p "Enter a command: " command; \
if [ "$$command" = "0" ] || [ "$$command" = "sqlite" ]; then \
if [ "$$command" = "1" ] || [ "$$command" = "sqlite" ]; then \
make gen-sqlite-prisma-schema; \
make sqlite-db-push; \
elif [ "$$command" = "1" ] || [ "$$command" = "postges" ] || [ "$$command" = "pg" ]; then \
elif [ "$$command" = "2" ] || [ "$$command" = "postges" ] || [ "$$command" = "pg" ]; then \
make gen-postgres-prisma-schema; \
make postgres-db-push; \
else echo "Unknown command."; fi
Expand Down Expand Up @@ -234,15 +243,33 @@ postgres-mode: ## postgres-mode
pnpm prisma-generate --schema ./prisma/postgres/schema.prisma; \
pnpm prisma-migrate deploy --schema ./prisma/postgres/schema.prisma

db-mode: ## db-mode
# Override environment variable files based on variables
RUN_DB_MODE ?= sqlite
FILE_ENV_PATHS = $(ENV_PATH)/.env.development* $(ENV_PATH)/.env.test*
switch.prisma.env:
ifeq ($(CI)-$(RUN_DB_MODE),0-sqlite)
@for file in $(FILE_ENV_PATHS); do \
sed -i~ 's~^PRISMA_DATABASE_URL=.*~PRISMA_DATABASE_URL=$(SQLITE_PRISMA_DATABASE_URL)~' $$file; \
done
else ifeq ($(CI)-$(RUN_DB_MODE),0-postges)
@for file in $(FILE_ENV_PATHS); do \
sed -i~ 's~^PRISMA_DATABASE_URL=.*~PRISMA_DATABASE_URL=$(POSTGES_PRISMA_DATABASE_URL)~' $$file; \
done
endif

switch-db-mode: ## Switch Database environment
$(print_db_mode_options)
@read -p "Enter a command: " command; \
if [ "$$command" = "sqlite" ]; then make sqlite-mode; \
elif [ "$$command" = "postges" ] || [ "$$command" = "pg" ]; then \
if [ "$$command" = "1" ] || [ "$$command" = "sqlite" ]; then \
make switch.prisma.env RUN_DB_MODE=sqlite; \
make sqlite-mode; \
elif [ "$$command" = "2" ] || [ "$$command" = "postges" ] || [ "$$command" = "pg" ]; then \
make switch.prisma.env RUN_DB_MODE=postges; \
make docker.up teable-postgres; \
make docker.await teable-postgres; \
make postgres-mode; \
else echo "Unknown command."; fi
else \
echo "Unknown command."; fi

help: ## show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,29 @@ Choose the Sql-database you like

# Run Project

#### 1. Install
#### 1. Initialize

```sh
yarn install
# Use `.nvmrc` file to specify node version(Requires pre `nvm` tools)
nvm install

# Enabling the Help Management Package Manager
corepack enable

# Install project dependencies
pnpm install

# Build packages
pnpm -F "./packages/**" run build
```

#### 2. DB migration
#### 2. Select Database

```sh
cd packages/db-main-prisma
# generate ts interface
yarn prisma generate
# create db schema
yarn prisma-db-push
make switch-db-mode
```

#### 3. Config .env file
#### 3. Custom environment variables(optional)

config openai ai endpoint and key

Expand All @@ -226,7 +232,7 @@ you should only start backend, it will start next server for front-end automatic
cd apps/nestjs-backend
tsc --build --watch
# run in a new terminal
yarn dev
pnpm dev
```

# Developers
Expand Down
6 changes: 3 additions & 3 deletions apps/nestjs-backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ const { getDefaultIgnorePatterns } = require('@teable-group/eslint-config-bases/

module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
project: 'tsconfig.eslint.json',
},
ignorePatterns: [...getDefaultIgnorePatterns(), '.dist', '.out'],
ignorePatterns: [...getDefaultIgnorePatterns()],
extends: [
'@teable-group/eslint-config-bases/typescript',
'@teable-group/eslint-config-bases/sonar',
'@teable-group/eslint-config-bases/regexp',
'@teable-group/eslint-config-bases/jest',
'@teable-group/eslint-config-bases/tailwind',
// Apply prettier and disable incompatible rules
'@teable-group/eslint-config-bases/prettier-plugin',
],
Expand Down
8 changes: 8 additions & 0 deletions apps/nestjs-backend/jest-e2e.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Config } from '@jest/types';
import { PrismaClient } from '@prisma/client';
import { parseDsn } from '@teable-group/core';
import * as bcrypt from 'bcrypt';
import * as dotenv from 'dotenv-flow';

interface ITestConfig {
driver: string;
Expand All @@ -18,11 +19,18 @@ declare global {
}

export default async (_globalConfig: Config.GlobalConfig, projectConfig: Config.ProjectConfig) => {
console.log('node-env', process.env.NODE_ENV);
dotenv.config({ path: '../nextjs-app' });

const { email, password, spaceId, baseId, userId } = projectConfig.globals
.testConfig as ITestConfig;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const databaseUrl = process.env.PRISMA_DATABASE_URL!;

console.log('database-url: ', databaseUrl);

const { driver } = parseDsn(databaseUrl);
console.log('driver: ', driver);
(projectConfig.globals.testConfig as ITestConfig).driver = driver;

const prismaClient = new PrismaClient();
Expand Down
1 change: 1 addition & 0 deletions apps/nestjs-backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"entryFile": "index",
Expand Down
Loading

0 comments on commit fd6f6ca

Please sign in to comment.