diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 385ce6524e..2eaad532df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -870,7 +870,7 @@ jobs: git clone --depth 1 https://github.com/vlang/gitly cd gitly ../v . - # ./gitly -ci_run #TODO + ./gitly -ci_run ../v -autofree . cd .. diff --git a/vlib/orm/orm.v b/vlib/orm/orm.v index 13f833809b..6a6afbb7c5 100644 --- a/vlib/orm/orm.v +++ b/vlib/orm/orm.v @@ -355,7 +355,7 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in stmt += ' NOT NULL' } if is_unique { - mut f := 'UNIQUE KEY($para$field.name$para' + mut f := 'UNIQUE($para$field.name$para' if ctyp == 'TEXT' && def_unique_len > 0 { if unique_len > 0 { f += '($unique_len)' diff --git a/vlib/orm/orm_fn_test.v b/vlib/orm/orm_fn_test.v index d74a0cb01c..e79b17567f 100644 --- a/vlib/orm/orm_fn_test.v +++ b/vlib/orm/orm_fn_test.v @@ -174,6 +174,85 @@ fn test_orm_table_gen() { }, ], sql_type_from_v, true) or { panic(err) } assert alt_query == "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='test_table' and xtype='U') CREATE TABLE 'test_table' ('id' SERIAL DEFAULT 10, 'test' TEXT, 'abc' INT64 DEFAULT 6754, PRIMARY KEY('id'));" + + unique_query := orm.orm_table_gen('test_table', "'", true, 0, [ + orm.TableField{ + name: 'id' + typ: 7 + default_val: '10' + attrs: [ + StructAttribute{ + name: 'primary' + }, + StructAttribute{ + name: 'sql' + has_arg: true + arg: 'serial' + kind: .plain + }, + ] + }, + orm.TableField{ + name: 'test' + typ: 18 + attrs: [ + StructAttribute{ + name: 'unique' + }, + ] + }, + orm.TableField{ + name: 'abc' + typ: 8 + default_val: '6754' + }, + ], sql_type_from_v, false) or { panic(err) } + assert unique_query == "CREATE TABLE IF NOT EXISTS 'test_table' ('id' SERIAL DEFAULT 10, 'test' TEXT, 'abc' INT64 DEFAULT 6754, PRIMARY KEY('id'), UNIQUE('test'));" + + mult_unique_query := orm.orm_table_gen('test_table', "'", true, 0, [ + orm.TableField{ + name: 'id' + typ: 7 + default_val: '10' + attrs: [ + StructAttribute{ + name: 'primary' + }, + StructAttribute{ + name: 'sql' + has_arg: true + arg: 'serial' + kind: .plain + }, + ] + }, + orm.TableField{ + name: 'test' + typ: 18 + attrs: [ + StructAttribute{ + name: 'unique' + has_arg: true + arg: 'test' + kind: .string + }, + ] + }, + orm.TableField{ + name: 'abc' + typ: 8 + default_val: '6754' + attrs: [ + StructAttribute{ + name: 'unique' + has_arg: true + arg: 'test' + kind: .string + }, + ] + }, + ], sql_type_from_v, false) or { panic(err) } + assert mult_unique_query == "CREATE TABLE IF NOT EXISTS 'test_table' ('id' SERIAL DEFAULT 10, 'test' TEXT, 'abc' INT64 DEFAULT 6754, /* test */UNIQUE('test', 'abc'), PRIMARY KEY('id'));" } fn sql_type_from_v(typ int) ?string {