user_authentication.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package models
  2. import (
  3. "database/sql"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/guregu/null"
  7. "gorm.io/gorm"
  8. )
  9. var (
  10. _ = time.Second
  11. _ = sql.LevelDefault
  12. _ = null.Bool{}
  13. _ = uuid.UUID{}
  14. )
  15. /*
  16. DB Table Details
  17. -------------------------------------
  18. CREATE TABLE `user_authentication` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `user_id` bigint(20) unsigned NOT NULL,
  21. `email` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  22. `password` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  23. `type` enum('google','kakao') COLLATE utf8mb4_bin DEFAULT NULL,
  24. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  25. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  26. `deleted_at` timestamp NULL DEFAULT NULL,
  27. PRIMARY KEY (`id`),
  28. UNIQUE KEY `id_UNIQUE` (`id`),
  29. KEY `fk_user_authentication_user1_idx` (`user_id`),
  30. CONSTRAINT `fk_user_authentication_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  31. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  32. JSON Sample
  33. -------------------------------------
  34. { "id": 5, "user_id": 26, "email": "qpDGdUEuBlasqubyCsnPRFgDQ", "password": "tmwRMgeOqmqwtXsFpOuYWmHPg", "type": "mxoTTHLJTmOObSRIUfinPYFDk", "created_at": "2126-02-16T07:26:20.136151635+09:00", "updated_at": "2050-06-23T09:54:05.591551141+09:00", "deleted_at": "2060-04-23T03:36:34.555847934+09:00"}
  35. Comments
  36. -------------------------------------
  37. [ 0] column is set for unsigned
  38. [ 1] column is set for unsigned
  39. */
  40. // UserAuthentication struct is a row record of the user_authentication table in the metarare database
  41. type UserAuthentication struct {
  42. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  43. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  44. //[ 1] user_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  45. UserID uint64 `gorm:"column:user_id;type:ubigint;" json:"user_id"`
  46. //[ 2] email varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  47. Email string `gorm:"column:email;type:varchar;size:256;" json:"email"`
  48. //[ 3] password varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  49. Password null.String `gorm:"column:password;type:varchar;size:256;" json:"password"`
  50. //[ 4] type char(6) null: true primary: false isArray: false auto: false col: char len: 6 default: []
  51. Type null.String `gorm:"column:type;type:char;size:6;" json:"type"`
  52. //[ 5] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  53. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  54. //[ 6] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  55. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  56. //[ 7] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  57. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  58. }
  59. var user_authenticationTableInfo = &TableInfo{
  60. Name: "user_authentication",
  61. Columns: []*ColumnInfo{
  62. &ColumnInfo{
  63. Index: 0,
  64. Name: "id",
  65. Comment: ``,
  66. Notes: `column is set for unsigned`,
  67. Nullable: false,
  68. DatabaseTypeName: "ubigint",
  69. DatabaseTypePretty: "ubigint",
  70. IsPrimaryKey: true,
  71. IsAutoIncrement: true,
  72. IsArray: false,
  73. ColumnType: "ubigint",
  74. ColumnLength: -1,
  75. GoFieldName: "ID",
  76. GoFieldType: "uint64",
  77. JSONFieldName: "id",
  78. ProtobufFieldName: "id",
  79. ProtobufType: "uint64",
  80. ProtobufPos: 1,
  81. },
  82. &ColumnInfo{
  83. Index: 1,
  84. Name: "user_id",
  85. Comment: ``,
  86. Notes: `column is set for unsigned`,
  87. Nullable: false,
  88. DatabaseTypeName: "ubigint",
  89. DatabaseTypePretty: "ubigint",
  90. IsPrimaryKey: false,
  91. IsAutoIncrement: false,
  92. IsArray: false,
  93. ColumnType: "ubigint",
  94. ColumnLength: -1,
  95. GoFieldName: "UserID",
  96. GoFieldType: "uint64",
  97. JSONFieldName: "user_id",
  98. ProtobufFieldName: "user_id",
  99. ProtobufType: "uint64",
  100. ProtobufPos: 2,
  101. },
  102. &ColumnInfo{
  103. Index: 2,
  104. Name: "email",
  105. Comment: ``,
  106. Notes: ``,
  107. Nullable: false,
  108. DatabaseTypeName: "varchar",
  109. DatabaseTypePretty: "varchar(256)",
  110. IsPrimaryKey: false,
  111. IsAutoIncrement: false,
  112. IsArray: false,
  113. ColumnType: "varchar",
  114. ColumnLength: 256,
  115. GoFieldName: "Email",
  116. GoFieldType: "string",
  117. JSONFieldName: "email",
  118. ProtobufFieldName: "email",
  119. ProtobufType: "string",
  120. ProtobufPos: 3,
  121. },
  122. &ColumnInfo{
  123. Index: 3,
  124. Name: "password",
  125. Comment: ``,
  126. Notes: ``,
  127. Nullable: true,
  128. DatabaseTypeName: "varchar",
  129. DatabaseTypePretty: "varchar(256)",
  130. IsPrimaryKey: false,
  131. IsAutoIncrement: false,
  132. IsArray: false,
  133. ColumnType: "varchar",
  134. ColumnLength: 256,
  135. GoFieldName: "Password",
  136. GoFieldType: "null.String",
  137. JSONFieldName: "password",
  138. ProtobufFieldName: "password",
  139. ProtobufType: "string",
  140. ProtobufPos: 4,
  141. },
  142. &ColumnInfo{
  143. Index: 4,
  144. Name: "type",
  145. Comment: ``,
  146. Notes: ``,
  147. Nullable: true,
  148. DatabaseTypeName: "char",
  149. DatabaseTypePretty: "char(6)",
  150. IsPrimaryKey: false,
  151. IsAutoIncrement: false,
  152. IsArray: false,
  153. ColumnType: "char",
  154. ColumnLength: 6,
  155. GoFieldName: "Type",
  156. GoFieldType: "null.String",
  157. JSONFieldName: "type",
  158. ProtobufFieldName: "type",
  159. ProtobufType: "string",
  160. ProtobufPos: 5,
  161. },
  162. &ColumnInfo{
  163. Index: 5,
  164. Name: "created_at",
  165. Comment: ``,
  166. Notes: ``,
  167. Nullable: false,
  168. DatabaseTypeName: "timestamp",
  169. DatabaseTypePretty: "timestamp",
  170. IsPrimaryKey: false,
  171. IsAutoIncrement: false,
  172. IsArray: false,
  173. ColumnType: "timestamp",
  174. ColumnLength: -1,
  175. GoFieldName: "CreatedAt",
  176. GoFieldType: "time.Time",
  177. JSONFieldName: "created_at",
  178. ProtobufFieldName: "created_at",
  179. ProtobufType: "uint64",
  180. ProtobufPos: 6,
  181. },
  182. &ColumnInfo{
  183. Index: 6,
  184. Name: "updated_at",
  185. Comment: ``,
  186. Notes: ``,
  187. Nullable: false,
  188. DatabaseTypeName: "timestamp",
  189. DatabaseTypePretty: "timestamp",
  190. IsPrimaryKey: false,
  191. IsAutoIncrement: false,
  192. IsArray: false,
  193. ColumnType: "timestamp",
  194. ColumnLength: -1,
  195. GoFieldName: "UpdatedAt",
  196. GoFieldType: "time.Time",
  197. JSONFieldName: "updated_at",
  198. ProtobufFieldName: "updated_at",
  199. ProtobufType: "uint64",
  200. ProtobufPos: 7,
  201. },
  202. &ColumnInfo{
  203. Index: 7,
  204. Name: "deleted_at",
  205. Comment: ``,
  206. Notes: ``,
  207. Nullable: true,
  208. DatabaseTypeName: "timestamp",
  209. DatabaseTypePretty: "timestamp",
  210. IsPrimaryKey: false,
  211. IsAutoIncrement: false,
  212. IsArray: false,
  213. ColumnType: "timestamp",
  214. ColumnLength: -1,
  215. GoFieldName: "DeletedAt",
  216. GoFieldType: "null.Time",
  217. JSONFieldName: "deleted_at",
  218. ProtobufFieldName: "deleted_at",
  219. ProtobufType: "uint64",
  220. ProtobufPos: 8,
  221. },
  222. },
  223. }
  224. // TableName sets the insert table name for this struct type
  225. func (u *UserAuthentication) TableName() string {
  226. return "user_authentication"
  227. }
  228. // BeforeSave invoked before saving, return an error if field is not populated.
  229. func (u *UserAuthentication) BeforeSave(*gorm.DB) error {
  230. return nil
  231. }
  232. // Prepare invoked before saving, can be used to populate fields etc.
  233. func (u *UserAuthentication) Prepare() {
  234. }
  235. // Validate invoked before performing action, return an error if field is not populated.
  236. func (u *UserAuthentication) Validate(action Action) error {
  237. return nil
  238. }
  239. // TableInfo return table meta data
  240. func (u *UserAuthentication) TableInfo() *TableInfo {
  241. return user_authenticationTableInfo
  242. }