Skip to content

Commit

Permalink
fix: only run local migrations on selected db (#795)
Browse files Browse the repository at this point in the history
* provide more detail when migration fails
* fix: only run migrations on selected database
  • Loading branch information
davemooreuws authored Oct 14, 2024
1 parent 47630a9 commit 4397213
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cli-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Run Tests
run: make test-coverage
- name: Upload Coverage Report
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: all.coverprofile
Expand Down
9 changes: 8 additions & 1 deletion pkg/cloud/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,14 @@ func (l *LocalSqlServer) BuildAndRunMigrations(fs afero.Fs, databasesToMigrate m

l.Publish(l.State)

err := l.migrationRunner(fs, l.State, databasesToMigrate)
servers := map[string]*DatabaseServer{}

// only run migrations for databases that are keys in databasesToMigrate
for dbName := range databasesToMigrate {
servers[dbName] = l.State[dbName]
}

err := l.migrationRunner(fs, servers, databasesToMigrate)
if err != nil {
return err
}
Expand Down
31 changes: 22 additions & 9 deletions pkg/dashboard/frontend/cypress/e2e/databases.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,19 @@ describe('Databases Spec', () => {
cy.getTestEl('run-btn').click()

cy.intercept('POST', '/api/sql', (req) => {
if (req.body && req.body.query === 'select * from test_table;') {
let body = req.body

if (typeof req.body === 'string') {
body = JSON.parse(req.body)
}

if (body && body.query.trim() === `select * from test_table;`) {
req.alias = 'query'
req.continue()
} else {
req.continue()
}
}).as('query')
})

cy.get('#sql-editor .cm-content', {
timeout: 5000,
Expand All @@ -259,6 +268,8 @@ describe('Databases Spec', () => {
})

it(`should of applied migrations for ${db}`, () => {
cy.wait(1000)

cy.get(`[data-rct-item-id="${db}"]`).click()

cy.wait(1000)
Expand All @@ -269,6 +280,14 @@ describe('Databases Spec', () => {

cy.wait('@migrate')

cy.get('#sql-editor .cm-content', {
timeout: 5000,
})
.clear({
force: true,
})
.invoke('html', 'select * from my_migration_table;')

cy.intercept('POST', '/api/sql', (req) => {
let body = req.body

Expand All @@ -284,13 +303,7 @@ describe('Databases Spec', () => {
}
})

cy.get('#sql-editor .cm-content', {
timeout: 5000,
})
.clear({
force: true,
})
.invoke('html', 'select * from my_migration_table;')
cy.wait(1000)

cy.getTestEl('run-btn').click()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ const DatabasesExplorer: React.FC = () => {
if (res.ok) {
toast.success('Migration successful', { id: loadingId })
} else {
toast.error('Migration failed', { id: loadingId })
const text = await res.text()
toast.error('Migration failed: ' + text, { id: loadingId })
}

setMigrationLoading(false)
Expand Down

0 comments on commit 4397213

Please sign in to comment.