Skip to content
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
35 changes: 15 additions & 20 deletions .github/workflows/cypress-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ jobs:
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot" --health-interval=10s --health-timeout=5s --health-retries=10

postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: fireback_test
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres -d fireback_test"
--health-interval=10s
--health-timeout=5s
--health-retries=10

steps:
- name: Checkout code
Expand Down Expand Up @@ -48,27 +62,8 @@ jobs:
- name: Install Fireback
run: sudo dpkg -i artifacts-ubuntu/fireback-server-all/fireback-amd64.deb

# - name: Setup Database
# run: |
# if [[ "${{ inputs.DB_TYPE }}" == "mysql" ]]; then
# fireback config db-dsn set root:root@tcp(localhost:3306)/fireback_test?charset=utf8mb4&parseTime=True&loc=Local
# fireback config db-vendor set mysql
# else
# fireback config db-name /tmp/database.db && \
# fireback config db-vendor set sqlite
# fi
# fireback migration apply


# - name: Add admin account
# run: fireback auth --in-root=true --value admin --workspace-type-id root --type email --password admin --first-name Ali --last-name Torabi
# - name: Check the passport
# run: fireback passport check-passport-methods



- name: Run Cypress tests
run: cd e2e && DB_TYPE=${{ inputs.DB_TYPE }} npm test
run: cd e2e && DB_TYPE=${{ inputs.DB_TYPE }} npm test

- name: Change the fireback replacement to github actions
run: cd e2e/samples/fireback-data-types && sed -i 's|/Users/ali/work/fireback|/home/runner/work/fireback/fireback|' go.mod
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/fireback-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ jobs:
uses: ./.github/workflows/cypress-test.yml
with:
DB_TYPE: mysql

run-cypress-postgres:
needs:
- build-ubuntu
uses: ./.github/workflows/cypress-test.yml
with:
DB_TYPE: postgres

run-cypress-sqlite:
needs:
Expand Down
37 changes: 34 additions & 3 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let firebackProcess; // Store the Fireback process reference

let BINARY = "/home/ali/work/fireback/app";
let CWD = "/home/ali/work/fireback";
const PORT = 7793;
const PORT = 7794;
let DB_VENDOR = "sqlite";
const isGitHubActions = !!process.env.GITHUB_ACTIONS;

Expand Down Expand Up @@ -62,19 +62,50 @@ module.exports = defineConfig({
await execAsync(`${BINARY} config db-vendor set mysql`, CWD);
await execAsync(
`${BINARY} config db-dsn set "root:root@tcp(localhost:3306)/fireback_test?charset=utf8mb4&parseTime=True&loc=Local"`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup mysql failed:", err);
}
} else if (vendor === "postgres") {
try {
console.log("Using postgres");
await execAsync(`${BINARY} config db-vendor set postgres`, CWD);

const dbName = "fireback_test";

// Drop and recreate database
console.log(
await execAsync(
`PGPASSWORD=postgres psql -U postgres -h localhost -p 5432 -d postgres -c "DROP DATABASE IF EXISTS ${dbName};"`,
CWD,
),
);

await execAsync(
`PGPASSWORD=postgres psql -U postgres -h localhost -p 5432 -d postgres -c "CREATE DATABASE ${dbName};"`,
CWD,
);

await execAsync(
`${BINARY} config db-dsn set "host=localhost user=postgres password=postgres dbname=${dbName} port=5432 sslmode=disable TimeZone=UTC"`,
CWD,
);

await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup postgres failed:", err);
}
} else {
await execAsync(`${BINARY} config db-vendor set sqlite`, CWD);
await execAsync(
`${BINARY} config db-name set /tmp/${dbname}.db`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

Expand Down
12 changes: 7 additions & 5 deletions e2e/cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Logging in with the signin", () => {
it("get the data of the public", () => {
cy.request(
"GET",
"http://localhost:7793/passports/available-methods"
"http://localhost:7794/passports/available-methods",
).then((response) => {
cy.task("log", response.body);
expect(response.body.data.item.email).to.equal(false);
Expand All @@ -38,7 +38,7 @@ describe("Logging in with the signin", () => {
it("get the data of the public", () => {
cy.request(
"GET",
"http://localhost:7793/passports/available-methods"
"http://localhost:7794/passports/available-methods",
).then((response) => {
cy.task("log", response.body);
expect(response.body.data.item.email).to.equal(true);
Expand All @@ -63,16 +63,17 @@ describe("Logging in with the signin", () => {
it("should be able to create a role in order to assign it into the workspace type.", () => {
cy.task(
"exec",
` role c --name testagentrole --capabilities "root.*"`
` role c --name testagentrole --capabilities "root.*"`,
).then((res) => {
console.log("Role created:", res)
console.log((roleId = JSON.parse(res).uniqueId));
});
});

it("should be able to create a workspace name", () => {
cy.task(
"exec",
` ws type c --title customer --slug customer --role-id ${roleId}`
` ws type c --title customer --slug customer --role-id ${roleId}`,
);
});

Expand Down Expand Up @@ -127,6 +128,7 @@ describe("Logging in with the signin", () => {

it("should be able to generate back the menu items from seeder.", () => {
cy.task("exec", `misc appmenu ssync`).then((content) => {
console.log(100, content);
let countFilesImported = 0;
for (const line of content.split("\n")) {
if (line.startsWith("Success")) {
Expand Down Expand Up @@ -184,7 +186,7 @@ describe("Logging in with the signin", () => {

cy.task(
"exec",
`misc appmenu q --query "unique_id = ${item.uniqueId}"`
`misc appmenu q --query "unique_id = ${item.uniqueId}"`,
).then((content) => {
const res = JSON.parse(content);
console.log(res);
Expand Down
2 changes: 1 addition & 1 deletion e2e/samples/fireback-data-types/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cloud.google.com/go/vision v1.2.0/go.mod h1:SmNwgObm5DpFBme2xpyOyasvBc1aPdjvMk2b
cloud.google.com/go/vision/v2 v2.2.0/go.mod h1:uCdV4PpN1S0jyCyq8sIM42v2Y6zOLkZs+4R9LrGYwFo=
cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xXZmFiHmGE=
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987794e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
github.com/474420502/gcurl v1.2.1 h1:Z+bAiOWdW7hbvTuBKxzhNuCevvvLlHDvk3hoSwHD2RA=
Expand Down
21 changes: 18 additions & 3 deletions e2e/samples/fireback-data-types/tests/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let firebackProcess; // Store the Fireback process reference

let BINARY = "/Users/ali/work/fireback/e2e/samples/fireback-data-types/app";
let CWD = "/Users/ali/work/fireback/e2e/samples/fireback-data-types";
const PORT = 7793;
const PORT = 7794;
let DB_VENDOR = "sqlite";
const isGitHubActions = !!process.env.GITHUB_ACTIONS;

Expand Down Expand Up @@ -61,19 +61,34 @@ module.exports = defineConfig({
await execAsync(`${BINARY} config db-vendor set mysql`, CWD);
await execAsync(
`${BINARY} config db-dsn set "root:root@tcp(localhost:3306)/fireback_test?charset=utf8mb4&parseTime=True&loc=Local"`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup mysql failed:", err);
}
} else if (vendor === "postgres") {
try {
await execAsync(`${BINARY} config db-vendor set postgres`, CWD);

await execAsync(
`${BINARY} config db-dsn set "host=localhost user=postgres password=postgres dbname=fireback_test port=5432 sslmode=disable TimeZone=UTC"`,
CWD,
);

await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup postgres failed:", err);
}
} else {
await execAsync(`${BINARY} config db-vendor set sqlite`, CWD);
await execAsync(
`${BINARY} config db-name set /tmp/${dbname}.db`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

Expand Down
2 changes: 1 addition & 1 deletion e2e/samples/fireback-payment/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cloud.google.com/go/vision v1.2.0/go.mod h1:SmNwgObm5DpFBme2xpyOyasvBc1aPdjvMk2b
cloud.google.com/go/vision/v2 v2.2.0/go.mod h1:uCdV4PpN1S0jyCyq8sIM42v2Y6zOLkZs+4R9LrGYwFo=
cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xXZmFiHmGE=
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987794e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
github.com/Azure/azure-storage-blob-go v0.14.0/go.mod h1:SMqIBi+SuiQH32bvyjngEewEeXoPfKMgWlBDaYf6fck=
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
Expand Down
21 changes: 18 additions & 3 deletions e2e/samples/fireback-payment/tests/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let firebackProcess; // Store the Fireback process reference

let BINARY = "/Users/ali/work/fireback/e2e/samples/fireback-payment/app";
let CWD = "/Users/ali/work/fireback/e2e/samples/fireback-payment";
const PORT = 7793;
const PORT = 7794;
let DB_VENDOR = "sqlite";
const isGitHubActions = !!process.env.GITHUB_ACTIONS;

Expand Down Expand Up @@ -61,19 +61,34 @@ module.exports = defineConfig({
await execAsync(`${BINARY} config db-vendor set mysql`, CWD);
await execAsync(
`${BINARY} config db-dsn set "root:root@tcp(localhost:3306)/fireback_test?charset=utf8mb4&parseTime=True&loc=Local"`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup mysql failed:", err);
}
} else if (vendor === "postgres") {
try {
await execAsync(`${BINARY} config db-vendor set postgres`, CWD);

await execAsync(
`${BINARY} config db-dsn set "host=localhost user=postgres password=postgres dbname=fireback_test port=5432 sslmode=disable TimeZone=UTC"`,
CWD,
);

await execAsync(`${BINARY} migration apply`, CWD);

return true;
} catch (err) {
console.error("setup postgres failed:", err);
}
} else {
await execAsync(`${BINARY} config db-vendor set sqlite`, CWD);
await execAsync(
`${BINARY} config db-name set /tmp/${dbname}.db`,
CWD
CWD,
);
await execAsync(`${BINARY} migration apply`, CWD);

Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cloud.google.com/go/vision v1.2.0/go.mod h1:SmNwgObm5DpFBme2xpyOyasvBc1aPdjvMk2b
cloud.google.com/go/vision/v2 v2.2.0/go.mod h1:uCdV4PpN1S0jyCyq8sIM42v2Y6zOLkZs+4R9LrGYwFo=
cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xXZmFiHmGE=
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987794e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
github.com/474420502/gcurl v1.2.1 h1:Z+bAiOWdW7hbvTuBKxzhNuCevvvLlHDvk3hoSwHD2RA=
Expand Down
35 changes: 32 additions & 3 deletions modules/abac/AppMenuEntity.dyno.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ var AppMenuEntityMetaConfig map[string]int64 = map[string]int64{}
var AppMenuEntityJsonSchema = fireback.ExtractEntityFields(reflect.ValueOf(&AppMenuEntity{}))

type AppMenuEntityPolyglot struct {
LinkerId string `gorm:"uniqueId;not null;size:100;" json:"linkerId,omitempty" yaml:"linkerId,omitempty" xml:"linkerId,omitempty"`
LanguageId string `gorm:"uniqueId;not null;size:100;" json:"languageId,omitempty" xml:"languageId,omitempty" yaml:"languageId,omitempty"`
LinkerId string `gorm:"not null;index:idx_linker_language_appMenu_AppMenuEntityPolyglot,unique" json:"linkerId,omitempty" yaml:"linkerId,omitempty" xml:"linkerId,omitempty"`
LanguageId string `gorm:"not null;index:idx_linker_language_appMenu_AppMenuEntityPolyglot,unique" json:"languageId,omitempty" xml:"languageId,omitempty" yaml:"languageId,omitempty"`
Label string `yaml:"label,omitempty" xml:"label,omitempty" json:"label,omitempty"`
}

Expand Down Expand Up @@ -461,7 +461,36 @@ func AppMenuActionCreateFn(dto *AppMenuEntity, query fireback.QueryDSL) (*AppMen
dbref = query.Tx
}
query.Tx = dbref
err := dbref.Create(&dto).Error
err := dbref.Transaction(func(tx *gorm.DB) error {
query.Tx = tx
if err := tx.
Omit("Translations").
Create(&dto).Error; err != nil {
return err
}
// create translations
if len(dto.Translations) > 0 {
for _, tr := range dto.Translations {
tr.LinkerId = dto.UniqueId
}
if tx.Dialector.Name() == "postgres" {
tx = tx.Clauses(clause.OnConflict{
Columns: []clause.Column{
{Name: "linker_id"},
{Name: "language_id"},
},
DoUpdates: clause.AssignmentColumns([]string{
"label",
}),
})
}
if err := tx.
Create(&dto.Translations).Error; err != nil {
return err
}
}
return nil
})
if err != nil {
err := fireback.GormErrorToIError(err)
return nil, err
Expand Down
35 changes: 32 additions & 3 deletions modules/abac/TimezoneGroupEntity.dyno.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ var TimezoneGroupEntityMetaConfig map[string]int64 = map[string]int64{}
var TimezoneGroupEntityJsonSchema = fireback.ExtractEntityFields(reflect.ValueOf(&TimezoneGroupEntity{}))

type TimezoneGroupEntityPolyglot struct {
LinkerId string `gorm:"uniqueId;not null;size:100;" json:"linkerId,omitempty" yaml:"linkerId,omitempty" xml:"linkerId,omitempty"`
LanguageId string `gorm:"uniqueId;not null;size:100;" json:"languageId,omitempty" xml:"languageId,omitempty" yaml:"languageId,omitempty"`
LinkerId string `gorm:"not null;index:idx_linker_language_timezoneGroup_TimezoneGroupEntityPolyglot,unique" json:"linkerId,omitempty" yaml:"linkerId,omitempty" xml:"linkerId,omitempty"`
LanguageId string `gorm:"not null;index:idx_linker_language_timezoneGroup_TimezoneGroupEntityPolyglot,unique" json:"languageId,omitempty" xml:"languageId,omitempty" yaml:"languageId,omitempty"`
Title string `yaml:"title,omitempty" xml:"title,omitempty" json:"title,omitempty"`
}

Expand Down Expand Up @@ -420,7 +420,36 @@ func TimezoneGroupActionCreateFn(dto *TimezoneGroupEntity, query fireback.QueryD
dbref = query.Tx
}
query.Tx = dbref
err := dbref.Create(&dto).Error
err := dbref.Transaction(func(tx *gorm.DB) error {
query.Tx = tx
if err := tx.
Omit("Translations").
Create(&dto).Error; err != nil {
return err
}
// create translations
if len(dto.Translations) > 0 {
for _, tr := range dto.Translations {
tr.LinkerId = dto.UniqueId
}
if tx.Dialector.Name() == "postgres" {
tx = tx.Clauses(clause.OnConflict{
Columns: []clause.Column{
{Name: "linker_id"},
{Name: "language_id"},
},
DoUpdates: clause.AssignmentColumns([]string{
"title",
}),
})
}
if err := tx.
Create(&dto.Translations).Error; err != nil {
return err
}
}
return nil
})
if err != nil {
err := fireback.GormErrorToIError(err)
return nil, err
Expand Down
Loading
Loading