-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first draft end to end Create API (#23)
* feat: Add a NoopLogger to help in tests * feat: Implement unmarshal in ItemsCreate * feat: Connect handler with repository * chore: Add docker compose file for local testing * feat: Add migrate command * refactor: Add metadata to Item, remove path and add back DisplayName * chore: Delete the docker compose, for now focus on sqlite
- Loading branch information
1 parent
1e20100
commit e529102
Showing
23 changed files
with
406 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,7 @@ docs/how_to_guides/* | |
# Notes | ||
TODO.md | ||
|
||
profile.cov | ||
profile.cov | ||
|
||
# Sqlite | ||
*.sqlite |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/glass-cms/glasscms/database" | ||
"github.com/lmittmann/tint" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type MigrateCommand struct { | ||
Command *cobra.Command | ||
logger *slog.Logger | ||
|
||
databaseConfig database.Config | ||
} | ||
|
||
func NewMigrateCommand() *MigrateCommand { | ||
mc := &MigrateCommand{ | ||
logger: slog.New( | ||
tint.NewHandler(os.Stdout, &tint.Options{ | ||
Level: slog.LevelDebug, | ||
}), | ||
), | ||
} | ||
|
||
mc.Command = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate the database schema", | ||
Hidden: true, | ||
RunE: mc.Execute, | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
flagset := mc.Command.Flags() | ||
|
||
flagset.StringVar( | ||
&mc.databaseConfig.Driver, | ||
database.ArgDriver, | ||
"", | ||
"The name of the database driver", | ||
) | ||
_ = viper.BindPFlag(database.ArgDriver, flagset.Lookup(database.ArgDriver)) | ||
|
||
flagset.StringVar( | ||
&mc.databaseConfig.DSN, | ||
database.ArgDSN, | ||
"", | ||
"The data source name (DSN) for the database", | ||
) | ||
_ = viper.BindPFlag(database.ArgDSN, flagset.Lookup(database.ArgDSN)) | ||
|
||
return mc | ||
} | ||
|
||
func (mc *MigrateCommand) Execute(_ *cobra.Command, _ []string) error { | ||
mc.logger.Info("Migrating the database schema") | ||
|
||
db, err := database.NewConnection(mc.databaseConfig) | ||
if err != nil { | ||
mc.logger.Error("Failed to create a new database connection") | ||
return err | ||
} | ||
|
||
return database.MigrateDatabase(db, mc.databaseConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
output: './out' | ||
database: | ||
dsn: 'file:test.db?cache=shared&mode=memory' | ||
dsn: 'file:test.sqlite?cache=shared' | ||
driver: 'sqlite3' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
-- +goose Up | ||
CREATE TABLE items ( | ||
uid TEXT PRIMARY KEY, | ||
name TEXT NOT NULL UNIQUE, | ||
display_name TEXT NOT NULL, | ||
create_time TIMESTAMP NOT NULL, | ||
update_time TIMESTAMP NOT NULL, | ||
delete_time TIMESTAMP, | ||
hash TEXT, | ||
name TEXT NOT NULL, | ||
path TEXT NOT NULL, | ||
content TEXT, | ||
properties JSON | ||
properties JSON, | ||
metadata JSON | ||
); | ||
|
||
CREATE INDEX items_name ON items(name); | ||
CREATE INDEX items_delete_time ON items(delete_time); | ||
|
||
-- +goose Down | ||
DROP TABLE items; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.