Skip to content

Commit 524daa7

Browse files
authored
Fixes (#595)
1 parent 464a97a commit 524daa7

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

mission-control

modules/crud/sql/describe.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ func (s *SQL) getDescribeDetails(ctx context.Context, project, col string) ([]ut
3434
args := []interface{}{}
3535
switch utils.DBType(s.dbType) {
3636
case utils.MySQL:
37-
queryString = `select column_name as 'Field', data_type as 'Type',is_nullable as 'Null',column_key as 'Key',coalesce(column_default,'') as 'Default',coalesce(column_default,'') as 'Extra'
38-
from information_schema.columns
39-
where (table_name,table_schema) = (?,?);`
37+
queryString = `select column_name as 'Field',is_nullable as 'Null',column_key as 'Key',coalesce(column_default,'') as 'Default',coalesce(column_default,'') as 'Extra',
38+
case when data_type = 'varchar' then concat(DATA_TYPE,'(',CHARACTER_MAXIMUM_LENGTH,')') else DATA_TYPE end as 'Type'
39+
from information_schema.columns
40+
where (table_name,table_schema) = (?,?);`
4041
args = append(args, col, project)
4142

4243
case utils.Postgres:

modules/eventing/handle_staged.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (m *Module) processStagedEvents(t *time.Time) {
5050
timestamp := eventDoc.Timestamp
5151
currentTimestamp := t.UTC().UnixNano() / int64(time.Millisecond)
5252

53-
if currentTimestamp > timestamp {
53+
if currentTimestamp >= timestamp {
5454
go m.processStagedEvent(eventDoc)
5555
}
5656
}
@@ -92,6 +92,7 @@ func (m *Module) processStagedEvent(eventDoc *model.EventDocument) {
9292
internalToken, err := m.auth.GetInternalAccessToken()
9393
if err != nil {
9494
log.Println("Eventing: Couldn't trigger functions -", err)
95+
return
9596
}
9697

9798
scToken, err := m.auth.GetSCAccessToken()
@@ -137,7 +138,7 @@ func (m *Module) processStagedEvent(eventDoc *model.EventDocument) {
137138
time.Sleep(5 * time.Second)
138139
}
139140

140-
if err := m.crud.InternalUpdate(ctx, m.config.DBType, m.project, m.config.Col, m.generateFailedEventRequest(eventDoc.ID, "Max retires limit reached")); err != nil {
141+
if err := m.crud.InternalUpdate(context.Background(), m.config.DBType, m.project, m.config.Col, m.generateFailedEventRequest(eventDoc.ID, "Max retires limit reached")); err != nil {
141142
log.Println("Eventing staged event handler could not update event doc:", err)
142143
}
143144
}

modules/schema/creation_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ func TestSchema_generateCreationQueries(t *testing.T) {
801801
currentSchema: schemaCollection{"table1": SchemaFields{"col1": &SchemaFieldType{FieldName: "col1", Kind: typeBoolean, IsDefault: true, Default: true}}},
802802
},
803803
fields: fields{crud: crudSqlServer, project: "test"},
804-
want: []string{"ALTER TABLE test.table1 ALTER COLUMN col1 DROP DEFAULT"},
804+
want: []string{"ALTER TABLE test.table1 DROP CONSTRAINT c_col1"},
805805
wantErr: false,
806806
},
807807
{

modules/schema/inspection.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ func generateInspection(dbType, col string, fields []utils.FieldType, foreignkey
8282

8383
if utils.DBType(dbType) == utils.Postgres {
8484
// split "'default-value'::text" to "default-value"
85-
s := strings.Split(field.FieldDefault, ",")
85+
s := strings.Split(field.FieldDefault, "::")
8686
field.FieldDefault = s[0]
87+
if fieldDetails.Kind == typeString || fieldDetails.Kind == typeDateTime || fieldDetails.Kind == TypeID {
88+
field.FieldDefault = strings.Split(field.FieldDefault, "'")[1]
89+
}
8790
}
8891

8992
// add string between quotes
90-
if fieldDetails.Kind == typeString {
93+
if fieldDetails.Kind == typeString || fieldDetails.Kind == TypeID || fieldDetails.Kind == typeDateTime {
9194
field.FieldDefault = fmt.Sprintf("\"%s\"", field.FieldDefault)
9295
}
9396
fieldDetails.Default = field.FieldDefault

modules/schema/template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package schema
22

33
import (
44
"bytes"
5-
"html/template"
5+
"text/template"
66
)
77

88
func generateSDL(schemaCol schemaCollection) (string, error) {

utils/handlers/graphql.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/gorilla/mux"
11+
1112
"github.com/spaceuptech/space-cloud/model"
1213
"github.com/spaceuptech/space-cloud/utils/graphql"
1314
)
@@ -29,9 +30,11 @@ func HandleGraphQLRequest(graphql *graphql.Module) http.HandlerFunc {
2930
json.NewDecoder(r.Body).Decode(&req)
3031
defer r.Body.Close()
3132

33+
w.Header().Set("Content-Type", "application/json")
34+
3235
if projectID != pid {
33-
//throw some error
34-
w.WriteHeader(http.StatusInternalServerError) //http status codee
36+
// throw some error
37+
w.WriteHeader(http.StatusInternalServerError)
3538
json.NewEncoder(w).Encode(map[string]string{"error": "project id doesn't match"})
3639
return
3740
}
@@ -49,7 +52,7 @@ func HandleGraphQLRequest(graphql *graphql.Module) http.HandlerFunc {
4952
return
5053
}
5154

52-
w.WriteHeader(http.StatusOK) //http status codee
55+
w.WriteHeader(http.StatusOK)
5356
json.NewEncoder(w).Encode(map[string]interface{}{"data": op})
5457
return
5558
})

0 commit comments

Comments
 (0)