Skip to content

Commit

Permalink
adding location to entries model, updating migrations, updating user-…
Browse files Browse the repository at this point in the history
…show template
  • Loading branch information
dmnyu committed Jul 17, 2024
1 parent da01cb5 commit 18785aa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
24 changes: 22 additions & 2 deletions database/migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package database

import (
"fmt"

"github.com/go-gormigrate/gormigrate/v2"
"github.com/nyudlts/go-medialog/config"
"github.com/nyudlts/go-medialog/models"
Expand All @@ -22,7 +24,8 @@ func MigrateDatabase(rollback bool, dbc config.DatabaseConfig) error {
if err := ConnectMySQL(dbc, true); err != nil {
return err
}
m := gormigrate.New(db, gormigrate.DefaultOptions, []*gormigrate.Migration{

migrations := []*gormigrate.Migration{
{
ID: "20240710 - Adding First Name",
Migrate: func(tx *gorm.DB) error { return tx.Migrator().AddColumn(&models.User{}, "FirstName") },
Expand All @@ -33,7 +36,14 @@ func MigrateDatabase(rollback bool, dbc config.DatabaseConfig) error {
Migrate: func(tx *gorm.DB) error { return tx.Migrator().AddColumn(&models.User{}, "LastName") },
Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropColumn(&models.User{}, "LastName") },
},
})
{
ID: "20240717 - Adding location to entry",
Migrate: func(tx *gorm.DB) error { return tx.Migrator().AddColumn(&models.Entry{}, "Location") },
Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropColumn(&models.Entry{}, "Location") },
},
}

m := gormigrate.New(db, gormigrate.DefaultOptions, migrations)

if rollback {
if err := m.RollbackLast(); err != nil {
Expand All @@ -44,6 +54,16 @@ func MigrateDatabase(rollback bool, dbc config.DatabaseConfig) error {
if err := m.Migrate(); err != nil {
return err
}
dbMigrations := []string{}
if err := db.Table("migrations").Find(&dbMigrations).Error; err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("DB Migration complete")
fmt.Println("Migrations currently applied")
for _, m := range dbMigrations {
fmt.Printf(" %s\n", m)
}
}
return nil
}
}
5 changes: 3 additions & 2 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Entry struct {
IsTransferred bool `json:"is_transferred"`
ContentType string `json:"content_type" form:"content_type"`
Structure string `json:"structure"`
Location string `json:"location" form:"location"`
}

func (e *Entry) UpdateEntry(updatedEntry Entry) {
Expand Down Expand Up @@ -144,8 +145,8 @@ type User struct {
UpdatedBy int `json:"updated_by"`
IsActive bool `json:"is_active"`
IsAdmin bool `json:"admin"`
CurrentIPAddress string `json: "current_ip_address"`
PreviousIPAddress string `json: "previous_ip_address"`
CurrentIPAddress string `json:"current_ip_address"`
PreviousIPAddress string `json:"previous_ip_address"`
FirstName string `json:"first_name" form:"first_name"`
LastName string `json:"last_name" form:"last_name"`
}
6 changes: 6 additions & 0 deletions templates/entries/entries-create.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ <h5 class="card-title">Image Data</h5>
</select>
</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Storage Location</strong></td>
<td class="col-sm-10">
<input type="text" id="location" name="location"/>
</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Interface</strong></td>
<td class="col-sm-10">
Expand Down
6 changes: 6 additions & 0 deletions templates/entries/entries-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ <h5 class="card-title">Image Data</h5>
</select>
</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Storage Location</strong></td>
<td class="col-sm-10">
<input type="text" id="location" name="location" value="{{ .entry.Location }}"/>
</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Interface</strong></td>
<td class="col-sm-10">
Expand Down
4 changes: 4 additions & 0 deletions templates/entries/entries-show.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ <h5 class="card-title">Image Data</h5>
<td class="col-sm-2"><strong>Image Format</strong></td>
<td class="col-sm-10">{{ .entry.ImageFormat }}</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Storage Location</strong></td>
<td class="col-sm-10">{{ .entry.Location }}</td>
</tr>
<tr>
<td class="col-sm-2"><strong>Interface</strong></td>
<td class="col-sm-10">{{ .entry.Interface }}</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/users/users-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 class="card-title">Users</h3>
{{ else }}
<a href="/users/{{ $user.ID }}/remove_admin" class="btn-sm btn-danger" type="button"/>Remove Admin</a>
{{ end }}
<a href="/users/{{ $user.ID}}/edit" class="btn btn-secondary">Edit</a>
<a href="/users/{{ $user.ID}}/edit" class="btn-small btn-secondary">Edit</a>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 18785aa

Please sign in to comment.