admin.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 `admin` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `name` varchar(128) COLLATE utf8mb4_bin NOT NULL,
  21. `status` enum('stable','blocked') COLLATE utf8mb4_bin NOT NULL DEFAULT 'stable',
  22. `email` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  23. `password` varchar(256) COLLATE utf8mb4_bin NOT 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. `phone` varchar(128) COLLATE utf8mb4_bin NOT NULL,
  28. `position` varchar(128) COLLATE utf8mb4_bin NOT NULL COMMENT '직책\n',
  29. `chargeof` varchar(128) COLLATE utf8mb4_bin NOT NULL COMMENT '담당업무',
  30. `team` varchar(128) COLLATE utf8mb4_bin NOT NULL COMMENT '소속(혹은 팀)\n',
  31. PRIMARY KEY (`id`),
  32. UNIQUE KEY `email_UNIQUE` (`email`),
  33. UNIQUE KEY `id_UNIQUE` (`id`)
  34. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  35. JSON Sample
  36. -------------------------------------
  37. { "id": 54, "name": "hZMeeyVVvQOGMhiGuJDVOVJlf", "status": "wLnXGWqWvFoAqLuuHpiJbXMRm", "email": "fjuKmMpcvMsOHjNXdvkGgAJRD", "password": "qULEnYAYAgpZmnEXbSuDAwVxh", "created_at": "2283-01-17T06:58:38.684502583+09:00", "updated_at": "2228-10-19T06:29:45.563913436+09:00", "deleted_at": "2078-11-18T01:47:30.911309112+09:00", "phone": "PVXHCxKkXNbFcNynvnMDECMdj", "position": "twEDuIAMswAxifODXmgDDlWtM", "chargeof": "ITwnLAYECkXnaoYNsJxlJCITq", "team": "dxkChksflqMuGvtaBpAHHLVsW"}
  38. Comments
  39. -------------------------------------
  40. [ 0] column is set for unsigned
  41. */
  42. // Admin struct is a row record of the admin table in the metarare database
  43. type Admin struct {
  44. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  45. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  46. //[ 1] name varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  47. Name string `gorm:"column:name;type:varchar;size:128;" json:"name"`
  48. //[ 2] status char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: [stable]
  49. Status string `gorm:"column:status;type:char;size:7;default:stable;" json:"status"`
  50. //[ 3] email varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  51. Email string `gorm:"column:email;type:varchar;size:256;" json:"email"`
  52. //[ 4] password varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  53. Password string `gorm:"column:password;type:varchar;size:256;" json:"password"`
  54. //[ 5] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  55. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  56. //[ 6] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  57. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  58. //[ 7] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  59. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  60. //[ 8] phone varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  61. Phone string `gorm:"column:phone;type:varchar;size:128;" json:"phone"`
  62. //[ 9] position varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  63. Position string `gorm:"column:position;type:varchar;size:128;" json:"position"` // 직책\n
  64. //[10] chargeof varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  65. Chargeof string `gorm:"column:chargeof;type:varchar;size:128;" json:"chargeof"` // 담당업무
  66. //[11] team varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  67. Team string `gorm:"column:team;type:varchar;size:128;" json:"team"` // 소속(혹은 팀)\n
  68. AdminPermission AdminPermission
  69. }
  70. var adminTableInfo = &TableInfo{
  71. Name: "admin",
  72. Columns: []*ColumnInfo{
  73. &ColumnInfo{
  74. Index: 0,
  75. Name: "id",
  76. Comment: ``,
  77. Notes: `column is set for unsigned`,
  78. Nullable: false,
  79. DatabaseTypeName: "ubigint",
  80. DatabaseTypePretty: "ubigint",
  81. IsPrimaryKey: true,
  82. IsAutoIncrement: true,
  83. IsArray: false,
  84. ColumnType: "ubigint",
  85. ColumnLength: -1,
  86. GoFieldName: "ID",
  87. GoFieldType: "uint64",
  88. JSONFieldName: "id",
  89. ProtobufFieldName: "id",
  90. ProtobufType: "uint64",
  91. ProtobufPos: 1,
  92. },
  93. &ColumnInfo{
  94. Index: 1,
  95. Name: "name",
  96. Comment: ``,
  97. Notes: ``,
  98. Nullable: false,
  99. DatabaseTypeName: "varchar",
  100. DatabaseTypePretty: "varchar(128)",
  101. IsPrimaryKey: false,
  102. IsAutoIncrement: false,
  103. IsArray: false,
  104. ColumnType: "varchar",
  105. ColumnLength: 128,
  106. GoFieldName: "Name",
  107. GoFieldType: "string",
  108. JSONFieldName: "name",
  109. ProtobufFieldName: "name",
  110. ProtobufType: "string",
  111. ProtobufPos: 2,
  112. },
  113. &ColumnInfo{
  114. Index: 2,
  115. Name: "status",
  116. Comment: ``,
  117. Notes: ``,
  118. Nullable: false,
  119. DatabaseTypeName: "char",
  120. DatabaseTypePretty: "char(7)",
  121. IsPrimaryKey: false,
  122. IsAutoIncrement: false,
  123. IsArray: false,
  124. ColumnType: "char",
  125. ColumnLength: 7,
  126. GoFieldName: "Status",
  127. GoFieldType: "string",
  128. JSONFieldName: "status",
  129. ProtobufFieldName: "status",
  130. ProtobufType: "string",
  131. ProtobufPos: 3,
  132. },
  133. &ColumnInfo{
  134. Index: 3,
  135. Name: "email",
  136. Comment: ``,
  137. Notes: ``,
  138. Nullable: false,
  139. DatabaseTypeName: "varchar",
  140. DatabaseTypePretty: "varchar(256)",
  141. IsPrimaryKey: false,
  142. IsAutoIncrement: false,
  143. IsArray: false,
  144. ColumnType: "varchar",
  145. ColumnLength: 256,
  146. GoFieldName: "Email",
  147. GoFieldType: "string",
  148. JSONFieldName: "email",
  149. ProtobufFieldName: "email",
  150. ProtobufType: "string",
  151. ProtobufPos: 4,
  152. },
  153. &ColumnInfo{
  154. Index: 4,
  155. Name: "password",
  156. Comment: ``,
  157. Notes: ``,
  158. Nullable: false,
  159. DatabaseTypeName: "varchar",
  160. DatabaseTypePretty: "varchar(256)",
  161. IsPrimaryKey: false,
  162. IsAutoIncrement: false,
  163. IsArray: false,
  164. ColumnType: "varchar",
  165. ColumnLength: 256,
  166. GoFieldName: "Password",
  167. GoFieldType: "string",
  168. JSONFieldName: "password",
  169. ProtobufFieldName: "password",
  170. ProtobufType: "string",
  171. ProtobufPos: 5,
  172. },
  173. &ColumnInfo{
  174. Index: 5,
  175. Name: "created_at",
  176. Comment: ``,
  177. Notes: ``,
  178. Nullable: false,
  179. DatabaseTypeName: "timestamp",
  180. DatabaseTypePretty: "timestamp",
  181. IsPrimaryKey: false,
  182. IsAutoIncrement: false,
  183. IsArray: false,
  184. ColumnType: "timestamp",
  185. ColumnLength: -1,
  186. GoFieldName: "CreatedAt",
  187. GoFieldType: "time.Time",
  188. JSONFieldName: "created_at",
  189. ProtobufFieldName: "created_at",
  190. ProtobufType: "uint64",
  191. ProtobufPos: 6,
  192. },
  193. &ColumnInfo{
  194. Index: 6,
  195. Name: "updated_at",
  196. Comment: ``,
  197. Notes: ``,
  198. Nullable: false,
  199. DatabaseTypeName: "timestamp",
  200. DatabaseTypePretty: "timestamp",
  201. IsPrimaryKey: false,
  202. IsAutoIncrement: false,
  203. IsArray: false,
  204. ColumnType: "timestamp",
  205. ColumnLength: -1,
  206. GoFieldName: "UpdatedAt",
  207. GoFieldType: "time.Time",
  208. JSONFieldName: "updated_at",
  209. ProtobufFieldName: "updated_at",
  210. ProtobufType: "uint64",
  211. ProtobufPos: 7,
  212. },
  213. &ColumnInfo{
  214. Index: 7,
  215. Name: "deleted_at",
  216. Comment: ``,
  217. Notes: ``,
  218. Nullable: true,
  219. DatabaseTypeName: "timestamp",
  220. DatabaseTypePretty: "timestamp",
  221. IsPrimaryKey: false,
  222. IsAutoIncrement: false,
  223. IsArray: false,
  224. ColumnType: "timestamp",
  225. ColumnLength: -1,
  226. GoFieldName: "DeletedAt",
  227. GoFieldType: "null.Time",
  228. JSONFieldName: "deleted_at",
  229. ProtobufFieldName: "deleted_at",
  230. ProtobufType: "uint64",
  231. ProtobufPos: 8,
  232. },
  233. &ColumnInfo{
  234. Index: 8,
  235. Name: "phone",
  236. Comment: ``,
  237. Notes: ``,
  238. Nullable: false,
  239. DatabaseTypeName: "varchar",
  240. DatabaseTypePretty: "varchar(128)",
  241. IsPrimaryKey: false,
  242. IsAutoIncrement: false,
  243. IsArray: false,
  244. ColumnType: "varchar",
  245. ColumnLength: 128,
  246. GoFieldName: "Phone",
  247. GoFieldType: "string",
  248. JSONFieldName: "phone",
  249. ProtobufFieldName: "phone",
  250. ProtobufType: "string",
  251. ProtobufPos: 9,
  252. },
  253. &ColumnInfo{
  254. Index: 9,
  255. Name: "position",
  256. Comment: `직책\n`,
  257. Notes: ``,
  258. Nullable: false,
  259. DatabaseTypeName: "varchar",
  260. DatabaseTypePretty: "varchar(128)",
  261. IsPrimaryKey: false,
  262. IsAutoIncrement: false,
  263. IsArray: false,
  264. ColumnType: "varchar",
  265. ColumnLength: 128,
  266. GoFieldName: "Position",
  267. GoFieldType: "string",
  268. JSONFieldName: "position",
  269. ProtobufFieldName: "position",
  270. ProtobufType: "string",
  271. ProtobufPos: 10,
  272. },
  273. &ColumnInfo{
  274. Index: 10,
  275. Name: "chargeof",
  276. Comment: `담당업무`,
  277. Notes: ``,
  278. Nullable: false,
  279. DatabaseTypeName: "varchar",
  280. DatabaseTypePretty: "varchar(128)",
  281. IsPrimaryKey: false,
  282. IsAutoIncrement: false,
  283. IsArray: false,
  284. ColumnType: "varchar",
  285. ColumnLength: 128,
  286. GoFieldName: "Chargeof",
  287. GoFieldType: "string",
  288. JSONFieldName: "chargeof",
  289. ProtobufFieldName: "chargeof",
  290. ProtobufType: "string",
  291. ProtobufPos: 11,
  292. },
  293. &ColumnInfo{
  294. Index: 11,
  295. Name: "team",
  296. Comment: `소속(혹은 팀)\n`,
  297. Notes: ``,
  298. Nullable: false,
  299. DatabaseTypeName: "varchar",
  300. DatabaseTypePretty: "varchar(128)",
  301. IsPrimaryKey: false,
  302. IsAutoIncrement: false,
  303. IsArray: false,
  304. ColumnType: "varchar",
  305. ColumnLength: 128,
  306. GoFieldName: "Team",
  307. GoFieldType: "string",
  308. JSONFieldName: "team",
  309. ProtobufFieldName: "team",
  310. ProtobufType: "string",
  311. ProtobufPos: 12,
  312. },
  313. },
  314. }
  315. // TableName sets the insert table name for this struct type
  316. func (a *Admin) TableName() string {
  317. return "admin"
  318. }
  319. // BeforeSave invoked before saving, return an error if field is not populated.
  320. func (a *Admin) BeforeSave(*gorm.DB) error {
  321. return nil
  322. }
  323. // Prepare invoked before saving, can be used to populate fields etc.
  324. func (a *Admin) Prepare() {
  325. }
  326. // Validate invoked before performing action, return an error if field is not populated.
  327. func (a *Admin) Validate(action Action) error {
  328. return nil
  329. }
  330. // TableInfo return table meta data
  331. func (a *Admin) TableInfo() *TableInfo {
  332. return adminTableInfo
  333. }