Start work on modules

v1
Andrew Sellers 5 years ago
parent 6816b31911
commit 87eb16c804
  1. 1
      cmd/build.go
  2. 98
      cmd/cmd.go
  3. 1
      cmd/dev.go
  4. 1
      cmd/generate.go
  5. 12
      homunculus/extend/extend.go
  6. 42
      homunculus/extend/ideas
  7. 112
      homunculus/migrations/migrator.go
  8. 19
      homunculus/modules/advanced_appointments/setup.go
  9. 19
      homunculus/modules/appointment_places/setup.go
  10. 19
      homunculus/modules/appointments/setup.go
  11. 19
      homunculus/modules/base/setup.go
  12. 19
      homunculus/modules/calsync/setup.go
  13. 19
      homunculus/modules/campaigns/setup.go
  14. 19
      homunculus/modules/example/setup.go
  15. 19
      homunculus/modules/feed/setup.go
  16. 19
      homunculus/modules/messages/setup.go
  17. 19
      homunculus/modules/outings/setup.go
  18. 19
      homunculus/modules/recurring_meetings/setup.go
  19. 19
      homunculus/modules/register.go
  20. 19
      homunculus/modules/scheduled_workflows/setup.go
  21. 19
      homunculus/modules/strategy/setup.go
  22. 9
      main.go

@ -0,0 +1 @@
package cmd

@ -0,0 +1,98 @@
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "faust",
Short: "faust is an application server",
Long: `faust is a framework for developing certain types
of web/mobile sites.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(`faust must have a command provided
dev - Run dev server
build - Take the current application and turn it into production things
generate - Generate a new faust application
version - Show which version you're using of faust`)
},
}
// later version names:
//
// early stuff
// Size isn't Everything
// Charming but Irrational
// Screw Loose
// God Told Me to Do It
// Demented by Determined
// Little Rascal
// Just Testing
// Beats Working
// Problem Child
// A Momentary Lapse of Sanity
// Teething Problems
// Youthful Indescretion
// Bad for Business
// Credibility Problem
// Pure Big Mad Boat Man
// Now We Try It My Way
// Gravitas Free Zone
// Nervous Energy
//
// mid stuff
// You'll Thank Me Later
// Big Sexy Beast
// Unacceptable Behavior
// Quietly Confident
// Zero Gravitas
// Limiting Factor
// But Who's Counting
// Me, I'm Counting
// You Naughty Monsters
// Questionable Ethics
// Revisionist
// Gunboat Diplomat
// Resistance is Character Forming
//
// later stuff
// Dressed Up to Party
// The Ends of Invention
// Sweet and Full of Grace
// Grey Area
// Cargo Cult
// Kiss My Ass
// I Said, I've Got a Big Stick
// Contents May Differ
// Subtle Shift of Emphasis
// You Call This Clean?
// Value Judgement
// Mistake Not...
//
// used version names:
//
// v1 Fate Amenable to Change
versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version string of faust",
Long: "faust might have odd verions, but you might want to know it",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("faust v1 Fate Amenable to Change")
},
}
)
func init() {
rootCmd.AddCommand(versionCmd)
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

@ -0,0 +1 @@
package cmd

@ -0,0 +1 @@
package cmd

@ -0,0 +1,12 @@
package extend
func RegisterModule(name string, builder func(*SiteConfig)) {
modules[name] = builder
}
var modules = make(map[string]func(*SiteConfig))
type SiteConfig struct {
Name string
Host string
}

@ -0,0 +1,42 @@
Extend Ideas
So you've got a module configuration and a site configuration
A module might will want to define components or extend components
from other modules.
A module might also define example pages for configurations to use.
So we need a component registry that defines all the components
for a particular set of modules
We'll also need a sitemap that defines how a specific configuration
is set up. Should probably add some site variables to customize things.
modules - SQL tables, new columns to existing SQL tables, etc.
Should modules be versioned? (in the future?)
Should probably be able to pass an arg map...
configurations - specific setups of modules + a sitemap
sitemap - Part of the configuration that defines how a site should
be set up.
sitevar - Allows limited modification of a sitemap per a hostname.
Maybe should be limited to strings and bools?
site - a hostname to sitemap + sitevars, maybe shouldn't be strictly
limited to hostname?
configuration
{
modules: [
{
name: "faust.base",
links: [{"users": ["categories", "tags"]}],
},
{
name: "faust.appointments",
cancellations: false,
available_times: false,
},
{
name: "faust.calsync",
google: false,
exchange: true
}
]
}

@ -14,6 +14,8 @@ type Migrator struct {
TableName string
Columns []Column
removes []Column
after []string
downafter []string
tx *sql.Tx
schema string
dir bool
@ -22,6 +24,7 @@ type Column struct {
Name string
Type ColumnType
Foreign string
Suffix string
}
// SQLDef returns the add column and add trigger definitions
@ -48,9 +51,10 @@ func (c Column) SQLDef(schema, table string) (string, string) {
}
if dt != "" {
return fmt.Sprintf(
`ADD COLUMN %s %s NOT NULL`,
`ADD COLUMN %s %s NOT NULL %s`,
c.Name,
dt,
c.Suffix,
), ""
}
switch c.Type {
@ -120,6 +124,106 @@ func (m *Migrator) ForeignKey(name, table string) *Migrator {
m.Columns = append(m.Columns, Column{Name: name, Type: ForeignKey, Foreign: table})
return m
}
func (m *Migrator) CheckColumn(name string, ct ColumnType, check string) *Migrator {
m.Columns = append(m.Columns,
Column{Name: name, Type: ct, Suffix: check},
)
return m
}
// Unique sets a column to have a unique constraint
func (m *Migrator) Unique(name string) *Migrator {
m.after = append(m.after, fmt.Sprintf(
"ALTER TABLE %s.%s ADD UNIQUE (%s)",
"%s",
m.TableName,
name,
))
m.downafter = append(m.downafter, fmt.Sprintf(
"ALTER TABLE DROP CONSTRAINT %s_%s_key",
"%s",
m.TableName,
name,
))
return m
}
//
func (m *Migrator) Nullable(name string) *Migrator {
m.after = append(m.after, fmt.Sprintf(
"ALTER TABLE %s.%s ALTER COLUMN %s DROP NOT NULL",
"%s",
m.TableName,
name,
))
m.downafter = append(m.downafter, fmt.Sprintf(
"ALTER TABLE %s.%s ALTER COLUMN %s SET NOT NULL",
"%s",
m.TableName,
name,
))
return m
}
func (m *Migrator) NotNull(name string) *Migrator {
m.after = append(m.after, fmt.Sprintf(
"ALTER TABLE %s.%s ALTER COLUMN %s SET NOT NULL",
"%s",
m.TableName,
name,
))
m.downafter = append(m.downafter, fmt.Sprintf(
"ALTER TABLE %s.%s ALTER COLUMN %s DROP NOT NULL",
"%s",
m.TableName,
name,
))
return m
}
func (m *Migrator) Index(cols ...string) *Migrator {
indexName := fmt.Sprintf("%s_%s", m.TableName, strings.Join(cols, "_"))
if len(indexName) > 62 {
indexName = m.TableName[:10]
cl := 50/len(cols) - 1
for _, col := range cols {
indexName += "_" + col[:cl]
}
}
m.after = append(m.after, fmt.Sprintf(
"CREATE INDEX %s ON %s.%s (%s)",
indexName,
"%s",
m.TableName,
strings.Join(cols, ", "),
))
m.downafter = append(m.downafter, fmt.Sprintf(
"DROP INDEX %s",
indexName,
))
return m
}
func (m *Migrator) DropIndex(cols ...string) *Migrator {
indexName := fmt.Sprintf("%s_%s", m.TableName, strings.Join(cols, "_"))
if len(indexName) > 62 {
indexName = m.TableName[:10]
cl := 50/len(cols) - 1
for _, col := range cols {
indexName += "_" + col[:cl]
}
}
m.downafter = append(m.downafter, fmt.Sprintf(
"CREATE INDEX %s ON %s.%s (%s)",
indexName,
"%s",
m.TableName,
strings.Join(cols, ", "),
))
m.after = append(m.after, fmt.Sprintf(
"DROP INDEX %s",
indexName,
))
return m
}
func (m *Migrator) Change(tx *sql.Tx, schema string, up bool) error {
m.tx, m.schema, m.dir = tx, schema, up
@ -163,6 +267,9 @@ Check:
actions := []string{}
afters := []string{}
for _, after := range m.after {
afters = append(afters, fmt.Sprintf(after, schema))
}
if len(removes) > 0 {
for _, rem := range removes {
actions = append(actions, "DROP COLUMN "+rem.Name)
@ -226,6 +333,9 @@ Check:
actions := []string{}
afters := []string{}
for _, da := range m.downafter {
afters = append(afters, fmt.Sprintf(da, schema))
}
if len(removes) > 0 {
for _, rem := range removes {
actions = append(actions, "DROP COLUMN "+rem.Name)

@ -0,0 +1,19 @@
package advancedappts
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Advanced Appointments",
URI: "faust.advanced_appts",
Setup: AdvancedApptsSetup,
Build: AdvancedApptsBuild,
})
}
func AdvancedApptsSetup() {
}
func AdvancedApptsBuild(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package apptplaces
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Appointment Places",
URI: "faust.appt_places",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package appointments
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Appointments",
URI: "faust.appointments",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package base
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Base Functionality",
URI: "faust.base",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package calsync
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Calendar Sync",
URI: "faust.calsync",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package campaigns
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Campaigns Module",
URI: "faust.campaigns",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package example
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Example Module",
URI: "faust.example",
Setup: ExampleSetup,
Build: ExampleBuild,
})
}
func ExampleSetup() {
}
func ExampleBuild(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package feed
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Feed Functionality",
URI: "faust.feed",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package messages
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Messages Module",
URI: "faust.messages",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package outings
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Outings Module",
URI: "faust.outings",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package recurrings
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Recurring Meetings",
URI: "faust.recurring_meetings",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package modules
type Module struct {
Name string
URI string
Setup func()
Build func(*Config, *Site)
}
type Config struct {
}
type Site struct {
}
var modules = make(map[string]*Module)
func Register(m *Module) {
modules[m.URI] = m
}

@ -0,0 +1,19 @@
package workflows
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Scheduled Workflows",
URI: "faust.scheduled_workflows",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,19 @@
package strategy
import "github.com/acsellers/faust/homunculus/modules"
func init() {
modules.Register(&modules.Module{
Name: "Strategy Module",
URI: "faust.strategy",
Setup: Setup,
Build: Build,
})
}
func Setup() {
}
func Build(c *modules.Config, s *modules.Site) {
}

@ -0,0 +1,9 @@
package main
import (
"github.com/acsellers/faust/cmd"
)
func main() {
cmd.Execute()
}
Loading…
Cancel
Save