Skip to content

Commit

Permalink
Merge pull request #19 from open-fidias/issue-18
Browse files Browse the repository at this point in the history
Upgrade of various packages
  • Loading branch information
atilacamurca authored Jun 23, 2018
2 parents 16617b5 + 1e42cf2 commit a074024
Show file tree
Hide file tree
Showing 19 changed files with 1,149 additions and 610 deletions.
18 changes: 9 additions & 9 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "db-migration-app",
"productName": "db-migration-app",
"version": "0.1.1",
"version": "0.1.2",
"description": "Desktop app to migrate databases based on SQL files",
"homepage": "https://github.com/open-fidias/db-migration-app",
"main": "./dist/main.js",
"dependencies": {
"bulma": "^0.4.2",
"date-fns": "^1.28.5",
"electron-settings": "^2.2.2",
"marv": "^1.4.2",
"marv-pg-driver": "^1.2.0",
"pg": "^6.2.4",
"vue": "^2.3.4",
"date-fns": "^1.29.0",
"electron-settings": "^3.2.0",
"marv": "^2.0.1",
"marv-pg-driver": "^2.0.0",
"pg": "^7.4.3",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
"vue-router": "^2.5.3",
"vuex": "^2.1.1"
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {},
"author": "Átila Camurça <camurca.home@gmail.com>",
Expand Down
22 changes: 4 additions & 18 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import { app, BrowserWindow, ipcMain, dialog } from 'electron'
import path from 'path'
import settings from 'electron-settings'

console.log('node electron version:', process.version)
console.log('NodeJS (from Electron) version:', process.version)

let mainWindow

Expand Down Expand Up @@ -42,24 +41,11 @@ function createWindow () {
mainWindow = null
})

settings.defaults({
connection: {
params: {
driver: 'postgresql',
host: 'localhost',
port: 5432,
database: 'postgres',
user: 'postgres'
}
},
migrations: {
folder: ''
}
})
settings.applyDefaults()
// config default settings
require('./settings')

// eslint-disable-next-line no-console
console.log('mainWindow opened')
console.log('Main Window opened')
}

app.on('ready', createWindow)
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import settings from 'electron-settings'

if (! settings.has('connection')) {
settings.set('connection', {
params: {
driver: 'postgresql',
host: 'localhost',
port: 5432,
database: 'postgres',
user: 'postgres'
}
})
}

if (! settings.has('migrations')) {
settings.set('migrations', {
folder: ''
})
}

if (! settings.has('preferences')) {
settings.set('preferences', {
goToMigrationsAfterConnect: true
})
}

console.log('Settings file:', settings.file())
18 changes: 5 additions & 13 deletions app/src/renderer/components/connection/ConnectionStatus.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="html">
<span class="tag" :class="style">
{{ status }}
<span class="tag" :class="connectionStatusStyle">
{{ connectionStatus }}
</span>
</template>

Expand All @@ -11,17 +11,9 @@ export default {
name: 'connection-status',
computed: {
...mapGetters([
'isConnected'
]),
style () {
return this.isConnected ? 'is-success' : 'is-danger'
},
status () {
return this.isConnected ? 'Connected' : 'Disconnect'
}
'connectionStatus',
'connectionStatusStyle'
])
}
}
</script>

<style lang="css">
</style>
46 changes: 29 additions & 17 deletions app/src/renderer/components/connection/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@

<div class="columns">
<div class="column">
<connection-status></connection-status>
<label class="checkbox">
<input type="checkbox"
v-model="goToMigrationsAfterConnect">
Go to Migrations after Connect
</label>
</div>
<div class="column">
<button class="button is-primary is-medium is-pulled-right"
Expand All @@ -80,15 +84,13 @@

<script>
import { mapMutations, mapGetters, mapActions } from 'vuex'
import ConnectionStatus from 'components/connection/ConnectionStatus'
import Notification from 'components/main/Notification'
import settings from 'electron-settings'
import { connect, disconnect } from '../../database.js'
export default {
name: 'connection-form',
components: {
ConnectionStatus,
Notification
},
data () {
Expand All @@ -109,41 +111,45 @@ export default {
message: '',
isVisible: false,
modifier: ''
}
},
goToMigrationsAfterConnect: false
}
},
mounted () {
settings.get('connection.params')
.then(values => {
this.form = values
this.form.password = this.getConnectionParams.password
})
this.setDefaultConnectionParams(settings.get('connection.params'))
this.goToMigrationsAfterConnect = settings.get('preferences.goToMigrationsAfterConnect', true)
},
methods: {
...mapMutations([
'setConnectionStatus'
'setConnectionStatus',
'setPostgresqlVersion'
]),
...mapActions([
'setConnectionParams'
]),
makeConnection () {
this.setConnectionParams(this.form)
this.setPostgresqlVersion(null)
disconnect()
.then(() => {
this.database.version = null
this.setConnectionStatus(false)
this.setConnectionStatus('is_connecting')
this.database.isConnecting = true
return connect(this.form)
})
.then((connection) => {
this.setConnectionStatus(connection.isConnected)
connection.instance.query('SELECT version()', (err, result) => {
this.setConnectionStatus(connection.isConnected ? 'connected' : 'disconnected')
connection.instance.query('show server_version', (err, result) => {
if (err) {
return this.showErrorMessage(err)
}
this.database.version = result.rows[0].version
this.database.version = result.rows[0].server_version
this.setPostgresqlVersion(this.database.version)
this.database.isConnecting = false
this.notification.isVisible = false
if (this.goToMigrationsAfterConnect) {
this.$router.push({name: 'migrations'})
}
})
})
.catch((err) => {
Expand All @@ -155,16 +161,22 @@ export default {
this.notification.message = `${err.severity} - ${err.message} [${err.code}]`
this.notification.isVisible = true
this.notification.modifier = 'is-danger'
},
setDefaultConnectionParams (values) {
this.form = values
this.form.password = this.getConnectionParams.password
}
},
computed: {
...mapGetters([
'getMigrationsFolder',
'getConnectionParams'
])
},
watch: {
goToMigrationsAfterConnect (newValue) {
settings.set('preferences.goToMigrationsAfterConnect', newValue)
}
}
}
</script>

<style lang="css">
</style>
16 changes: 16 additions & 0 deletions app/src/renderer/components/connection/PostgresqlVersion.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template lang="html">
<span class="tag is-light">PostgreSQL {{ postgresqlVersion }}</span>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
name: 'postgresql-version',
computed: {
...mapGetters([
'postgresqlVersion'
])
}
}
</script>
27 changes: 24 additions & 3 deletions app/src/renderer/components/main/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<nav class="nav has-shadow is-inverted">
<div class="container">
<div class="nav-left">
<a href="#" class="nav-item">
<router-link :to="{name: 'home-page'}" class="nav-item">
<img src="./assets/logo.svg" alt="logo">
</a>
</router-link>
<router-link
class="nav-item is-tab"
active-class="is-active"
Expand All @@ -14,14 +14,35 @@
active-class="is-active"
to="/migrations">Migrations</router-link>
</div>
<div class="nav-right">
<div class="nav-item">
<connection-status></connection-status>
</div>
<div class="nav-item">
<postgresql-version v-show="isConnected"></postgresql-version>
</div>
</div>
</div>
</nav>
</template>

<script>
import ConnectionStatus from 'components/connection/ConnectionStatus'
import PostgresqlVersion from 'components/connection/PostgresqlVersion'
import {mapGetters} from 'vuex'
export default {
name: 'main-menu'
name: 'main-menu',
components: {
ConnectionStatus,
PostgresqlVersion
},
computed: {
...mapGetters([
'isConnected'
])
}
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/components/main/Versions.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<p v-once>
You are using electron v{{ versions['atom-shell'] }}
with node v{{ versions.node }} on the {{ platform }} platform.
You are using electron {{ versions['electron'] }}
with node {{ versions.node }} on the {{ platform }} platform.
</p>
</template>

Expand Down
4 changes: 1 addition & 3 deletions app/src/renderer/components/migration/MigrationContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<section class="section">
<migration-folder></migration-folder>
<migration-list></migration-list>
<p>Showing only the last 50</p>
</section>
</template>

Expand All @@ -17,6 +18,3 @@ export default {
}
}
</script>

<style lang="css">
</style>
8 changes: 1 addition & 7 deletions app/src/renderer/components/migration/MigrationFolder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const dialog = remote.dialog
export default {
name: 'migration-folder',
mounted () {
settings.get('migrations.folder')
.then(folder => {
this.setupMigrationFolder(folder)
})
this.setupMigrationFolder(settings.get('migrations.folder'))
},
methods: {
chooseFolder () {
Expand All @@ -57,6 +54,3 @@ export default {
}
}
</script>

<style lang="css">
</style>
2 changes: 1 addition & 1 deletion app/src/renderer/components/migration/MigrationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default {
},
fetchList (connection) {
const sql = `SELECT level, comment, "timestamp", checksum
FROM migrations ORDER BY "timestamp" DESC LIMIT 50`
FROM migrations ORDER BY level DESC LIMIT 50`
connection.instance.query(sql, (err, result) => {
if (err) {
return this.showErrorMessage(err)
Expand Down
24 changes: 23 additions & 1 deletion app/src/renderer/vuex/getters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@

const connection = {
status: {
disconnected: 'Disconnect',
is_connecting: 'Is connecting...',
connected: 'Connected'
},
style: {
disconnected: 'is-danger',
is_connecting: 'is-info',
connected: 'is-success'
}
}

export default {
getMigrationsFolder (state) {
return state.migrations.folder
},
isConnected (state) {
return state.connection.isConnected
return state.connection.status === 'connected'
},
getConnectionParams (state) {
return state.connection.params
},
connectionStatus (state) {
return connection.status[state.connection.status]
},
connectionStatusStyle (state) {
return connection.style[state.connection.status]
},
postgresqlVersion (state) {
return state.postgresql.version
}
}
Loading

0 comments on commit a074024

Please sign in to comment.